Go patch committed: Don't permit go/defer calls to be parenthesized

Submitted by Ian Taylor on Dec. 4, 2012, 12:28 a.m.

Details

Message ID mcrr4n6slse.fsf@google.com
State New
Headers show

Commit Message

Ian Taylor Dec. 4, 2012, 12:28 a.m.
The Go language spec does not permit go or defer calls to be
parenthesized, but gccgo was permitting it.  This patch issues an error
for that case.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch hide | download patch | download mbox

diff -r 4427b2edf858 go/parse.cc
--- a/go/parse.cc	Sun Dec 02 23:20:02 2012 -0800
+++ b/go/parse.cc	Mon Dec 03 16:26:16 2012 -0800
@@ -4089,13 +4089,16 @@ 
 	     || this->peek_token()->is_keyword(KEYWORD_DEFER));
   bool is_go = this->peek_token()->is_keyword(KEYWORD_GO);
   Location stat_location = this->location();
-  this->advance_token();
+
+  const Token* token = this->advance_token();
   Location expr_location = this->location();
+  bool is_parenthesized = token->is_op(OPERATOR_LPAREN);
+
   Expression* expr = this->expression(PRECEDENCE_NORMAL, false, true, NULL);
   Call_expression* call_expr = expr->call_expression();
-  if (call_expr == NULL)
-    {
-      error_at(expr_location, "expected call expression");
+  if (is_parenthesized || call_expr == NULL)
+    {
+      error_at(expr_location, "argument to go/defer must be function call");
       return;
     }