Commit c414667b by Ian Lance Taylor

compiler: reject NOT operator on integer types.

The Go specification only accepts the NOT operator on boolean
types.

Fixes issue 10.

From-SVN: r187262
parent 55796e90
...@@ -3606,8 +3606,7 @@ Unary_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int) ...@@ -3606,8 +3606,7 @@ Unary_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
return Expression::make_error(this->location()); return Expression::make_error(this->location());
} }
if (op == OPERATOR_PLUS || op == OPERATOR_MINUS if (op == OPERATOR_PLUS || op == OPERATOR_MINUS || op == OPERATOR_XOR)
|| op == OPERATOR_NOT || op == OPERATOR_XOR)
{ {
Numeric_constant nc; Numeric_constant nc;
if (expr->numeric_constant_value(&nc)) if (expr->numeric_constant_value(&nc))
...@@ -3697,10 +3696,10 @@ Unary_expression::eval_constant(Operator op, const Numeric_constant* unc, ...@@ -3697,10 +3696,10 @@ Unary_expression::eval_constant(Operator op, const Numeric_constant* unc,
else else
go_unreachable(); go_unreachable();
case OPERATOR_NOT:
case OPERATOR_XOR: case OPERATOR_XOR:
break; break;
case OPERATOR_NOT:
case OPERATOR_AND: case OPERATOR_AND:
case OPERATOR_MULT: case OPERATOR_MULT:
return false; return false;
...@@ -3911,6 +3910,10 @@ Unary_expression::do_check_types(Gogo*) ...@@ -3911,6 +3910,10 @@ Unary_expression::do_check_types(Gogo*)
break; break;
case OPERATOR_NOT: case OPERATOR_NOT:
if (!type->is_boolean_type())
this->report_error(_("expected boolean type"));
break;
case OPERATOR_XOR: case OPERATOR_XOR:
if (type->integer_type() == NULL if (type->integer_type() == NULL
&& !type->is_boolean_type()) && !type->is_boolean_type())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment