Patchwork [gccgo] Permit trailing comma after call arguments

login
register
mail settings
Submitter Ian Taylor
Date June 22, 2010, 10:21 p.m.
Message ID <mcrmxumk8td.fsf@dhcp-172-17-9-151.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/56576/
State New
Headers show

Comments

Ian Taylor - June 22, 2010, 10:21 p.m.
Go permits a trailing comma after call arguments (e.g., "fn(1,)").
gccgo failed to implement that.  This patch fixes it.  Committed to
gccgo branch.

Ian

Patch

diff -r d52e86ca34e6 go/parse.cc
--- a/go/parse.cc	Tue Jun 22 14:49:01 2010 -0700
+++ b/go/parse.cc	Tue Jun 22 15:18:58 2010 -0700
@@ -141,7 +141,7 @@ 
       if (!token->is_op(OPERATOR_COMMA))
 	return ret;
 
-      // A trailing comma is permitted in CompositeLit.
+      // Most expression lists permit a trailing comma.
       source_location location = token->location();
       this->advance_token();
       if (!this->expression_may_start_here())
@@ -2613,7 +2613,7 @@ 
   return Expression::make_index(expr, start, end, location);
 }
 
-// Call = "(" [ ExpressionList ] ")" .
+// Call = "(" [ ExpressionList [ "," ] ] ")" .
 
 Expression*
 Parse::call(Expression* func)
@@ -2626,6 +2626,8 @@ 
       args = this->expression_list(NULL, false);
       token = this->peek_token();
     }
+  if (token->is_op(OPERATOR_COMMA))
+    token = this->advance_token();
   if (!token->is_op(OPERATOR_RPAREN))
     this->error("missing %<)%>");
   else