This is the mail archive of the
mailing list for the GCC project.
Go patch committed: Reject invalid composite literals
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Tue, 24 Apr 2012 07:54:34 -0700
- Subject: Go patch committed: Reject invalid composite literals
This patch to the Go frontend adds a check to reject composite literals
that the language syntax forbids. The parser was able to parse some
cases unambiguously because it already knew that some name was a type,
but since that can not always be known that parse is not permitted.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.7 branch.
diff -r 91db663343df go/parse.cc
--- a/go/parse.cc Mon Apr 23 22:54:27 2012 -0700
+++ b/go/parse.cc Tue Apr 24 07:50:51 2012 -0700
@@ -2865,7 +2865,16 @@
- if (is_parenthesized)
+ if (!may_be_composite_lit)
+ Type* t = ret->type();
+ if (t->named_type() != NULL
+ || t->forward_declaration_type() != NULL)
+ _("parentheses required around this composite literal"
+ "to avoid parsing ambiguity"));
+ else if (is_parenthesized)
"cannot parenthesize type in composite literal");
ret = this->composite_lit(ret->type(), 0, ret->location());