OSDN Git Service

compiler: reject NOT operator on integer types.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 May 2012 18:24:32 +0000 (18:24 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 May 2012 18:24:32 +0000 (18:24 +0000)
The Go specification only accepts the NOT operator on boolean
types.

Fixes issue 10.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@187263 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/expressions.cc

index a266694..39824bf 100644 (file)
@@ -3606,8 +3606,7 @@ Unary_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
       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 @@ Unary_expression::eval_constant(Operator op, const Numeric_constant* unc,
       else
        go_unreachable();
 
-    case OPERATOR_NOT:
     case OPERATOR_XOR:
       break;
 
+    case OPERATOR_NOT:
     case OPERATOR_AND:
     case OPERATOR_MULT:
       return false;
@@ -3911,6 +3910,10 @@ Unary_expression::do_check_types(Gogo*)
       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())