OSDN Git Service

compiler: Reject invalid composite literals.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 24 Apr 2012 14:54:32 +0000 (14:54 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 24 Apr 2012 14:54:32 +0000 (14:54 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@186767 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/parse.cc

index 7207db5..7a567a1 100644 (file)
@@ -2865,7 +2865,16 @@ Parse::primary_expr(bool may_be_sink, bool may_be_composite_lit,
     {
       if (this->peek_token()->is_op(OPERATOR_LCURLY))
        {
-         if (is_parenthesized)
+         if (!may_be_composite_lit)
+           {
+             Type* t = ret->type();
+             if (t->named_type() != NULL
+                 || t->forward_declaration_type() != NULL)
+               error_at(start_loc,
+                        _("parentheses required around this composite literal"
+                          "to avoid parsing ambiguity"));
+           }
+         else if (is_parenthesized)
            error_at(start_loc,
                     "cannot parenthesize type in composite literal");
          ret = this->composite_lit(ret->type(), 0, ret->location());