OSDN Git Service

compiler: Better warning for switch on non-comparable type.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 24 Sep 2012 22:21:58 +0000 (22:21 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 24 Sep 2012 22:21:58 +0000 (22:21 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@191684 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/statements.cc

index fa7f208..a96e6bd 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())