diff mbox

Go patch committed: Don't permit !0

Message ID mcrwr4nj1co.fsf@dhcp-172-18-216-180.mtv.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor May 7, 2012, 6:24 p.m. UTC
This patch from Rémy Oudompheng fixes a bug in the Go frontend: it was
permitting the ! unary operator with integer operands, but in the Go
language ! is only permitted with boolean operands.  Bootstrapped and
ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to mainline and
4.7 branch.

Ian
diff mbox

Patch

diff -r 838f1f13015d go/expressions.cc
--- a/go/expressions.cc	Fri May 04 12:30:49 2012 -0700
+++ b/go/expressions.cc	Mon May 07 11:19:42 2012 -0700
@@ -3606,8 +3606,7 @@ 
       return Expression::make_error(this->location());
     }
 
-  if (op == OPERATOR_PLUS || op == OPERATOR_MINUS
-      || op == OPERATOR_NOT || op == OPERATOR_XOR)
+  if (op == OPERATOR_PLUS || op == OPERATOR_MINUS || op == OPERATOR_XOR)
     {
       Numeric_constant nc;
       if (expr->numeric_constant_value(&nc))
@@ -3697,10 +3696,10 @@ 
       else
 	go_unreachable();
 
+    case OPERATOR_XOR:
+      break;
+
     case OPERATOR_NOT:
-    case OPERATOR_XOR:
-      break;
-
     case OPERATOR_AND:
     case OPERATOR_MULT:
       return false;
@@ -3911,6 +3910,10 @@ 
       break;
 
     case OPERATOR_NOT:
+      if (!type->is_boolean_type())
+	this->report_error(_("expected boolean type"));
+      break;
+
     case OPERATOR_XOR:
       if (type->integer_type() == NULL
 	  && !type->is_boolean_type())