]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compiler: Better warning for switch on non-comparable type.
authorIan Lance Taylor <ian@gcc.gnu.org>
Mon, 24 Sep 2012 22:21:49 +0000 (22:21 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Mon, 24 Sep 2012 22:21:49 +0000 (22:21 +0000)
From-SVN: r191683

gcc/go/gofrontend/statements.cc

index fa7f20836ad26d9a412ca654528fea554fe50cce..a96e6bd655952e335c2af320835ec0206dff181a 100644 (file)
@@ -3846,6 +3846,16 @@ Switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
     return new Constant_switch_statement(this->val_, this->clauses_,
                                         this->break_label_, loc);
 
+  if (this->val_ != NULL
+      && !this->val_->type()->is_comparable()
+      && !Type::are_compatible_for_comparison(true, this->val_->type(),
+                                             Type::make_nil_type(), NULL))
+    {
+      error_at(this->val_->location(),
+              "cannot switch on value whose type that may not be compared");
+      return Statement::make_error_statement(loc);
+    }
+
   Block* b = new Block(enclosing, loc);
 
   if (this->clauses_->empty())