From: Ian Lance Taylor Date: Mon, 24 Sep 2012 22:21:49 +0000 (+0000) Subject: compiler: Better warning for switch on non-comparable type. X-Git-Tag: misc/gccgo-go1_1_2~660 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90f01468b4c82e895f43432ea6b1504d47d0a294;p=thirdparty%2Fgcc.git compiler: Better warning for switch on non-comparable type. From-SVN: r191683 --- diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index fa7f20836ad2..a96e6bd65595 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -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())