Hi,

should we do something like this? Tested x86_64-linux.

Thanks,
Paolo.

////////////////
2014-06-26  Paolo Carlini  <paolo.carl...@oracle.com>

        * parser.c (cp_parser_compound_literal_p): New.
        (cp_parser_postfix_expression, cp_parser_sizeof_operand): Use it.
Index: parser.c
===================================================================
--- parser.c    (revision 212052)
+++ parser.c    (working copy)
@@ -5609,6 +5609,30 @@ cp_parser_qualifying_entity (cp_parser *parser,
   return scope;
 }
 
+/* Return true if we are looking at a compound-literal, false otherwise.  */
+
+static bool
+cp_parser_compound_literal_p (cp_parser *parser)
+{
+  /* Consume the `('.  */
+  cp_lexer_consume_token (parser->lexer);
+
+  cp_lexer_save_tokens (parser->lexer);
+
+  /* Skip tokens until the next token is a closing parenthesis.
+     If we find the closing `)', and the next token is a `{', then
+     we are looking at a compound-literal.  */
+  bool compound_literal_p
+    = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
+                                             /*consume_paren=*/true)
+       && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
+  
+  /* Roll back the tokens we skipped.  */
+  cp_lexer_rollback_tokens (parser->lexer);
+
+  return compound_literal_p;
+}
+
 /* Parse a postfix-expression.
 
    postfix-expression:
@@ -5917,25 +5941,12 @@ cp_parser_postfix_expression (cp_parser *parser, b
            && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
          {
            tree initializer = NULL_TREE;
-           bool compound_literal_p;
 
            cp_parser_parse_tentatively (parser);
-           /* Consume the `('.  */
-           cp_lexer_consume_token (parser->lexer);
 
            /* Avoid calling cp_parser_type_id pointlessly, see comment
               in cp_parser_cast_expression about c++/29234.  */
-           cp_lexer_save_tokens (parser->lexer);
-
-           compound_literal_p
-             = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
-                                                       /*consume_paren=*/true)
-                && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
-
-           /* Roll back the tokens we skipped.  */
-           cp_lexer_rollback_tokens (parser->lexer);
-
-           if (!compound_literal_p)
+           if (!cp_parser_compound_literal_p (parser))
              cp_parser_simulate_error (parser);
            else
              {
@@ -23966,31 +23977,15 @@ cp_parser_sizeof_operand (cp_parser* parser, enum
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
     {
       tree type = NULL_TREE;
-      bool compound_literal_p;
 
       /* We can't be sure yet whether we're looking at a type-id or an
         expression.  */
       cp_parser_parse_tentatively (parser);
-      /* Consume the `('.  */
-      cp_lexer_consume_token (parser->lexer);
       /* Note: as a GNU Extension, compound literals are considered
         postfix-expressions as they are in C99, so they are valid
         arguments to sizeof.  See comment in cp_parser_cast_expression
         for details.  */
-      cp_lexer_save_tokens (parser->lexer);
-      /* Skip tokens until the next token is a closing parenthesis.
-        If we find the closing `)', and the next token is a `{', then
-        we are looking at a compound-literal.  */
-      compound_literal_p
-       = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
-                                                 /*consume_paren=*/true)
-          && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
-      /* Roll back the tokens we skipped.  */
-      cp_lexer_rollback_tokens (parser->lexer);
-      /* If we were looking at a compound-literal, simulate an error
-        so that the call to cp_parser_parse_definitely below will
-        fail.  */
-      if (compound_literal_p)
+      if (cp_parser_compound_literal_p (parser))
        cp_parser_simulate_error (parser);
       else
        {

Reply via email to