diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-09-24 22:21:49 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-09-24 22:21:49 +0000 |
commit | 4f85f6f124842452c1fc3918866a4fe17bd34413 (patch) | |
tree | ba1e66b9f76afe592b6452d54dedc6dc360016a4 | |
parent | 524f019b6114fa27293af7e4212136d5257d7b9c (diff) | |
download | gcc-4f85f6f124842452c1fc3918866a4fe17bd34413.tar.gz |
compiler: Better warning for switch on non-comparable type.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@191683 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/go/gofrontend/statements.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index fa7f20836ad..a96e6bd6559 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()) |