mirror of git://gcc.gnu.org/git/gcc.git
				
				
				
			parser.c (cp_parser_compound_literal_p): New.
2014-06-27 Paolo Carlini <paolo.carlini@oracle.com> * parser.c (cp_parser_compound_literal_p): New. (cp_parser_postfix_expression, cp_parser_sizeof_operand): Use it. From-SVN: r212064
This commit is contained in:
		
							parent
							
								
									a4ee446d6d
								
							
						
					
					
						commit
						fcbbf14a65
					
				| 
						 | 
					@ -1,3 +1,8 @@
 | 
				
			||||||
 | 
					2014-06-27  Paolo Carlini  <paolo.carlini@oracle.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* parser.c (cp_parser_compound_literal_p): New.
 | 
				
			||||||
 | 
						(cp_parser_postfix_expression, cp_parser_sizeof_operand): Use it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2014-06-26  Jason Merrill  <jason@redhat.com>
 | 
					2014-06-26  Jason Merrill  <jason@redhat.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	* parser.c (cp_parser_for_init_statement): Change range-for error
 | 
						* parser.c (cp_parser_for_init_statement): Change range-for error
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2480,7 +2480,9 @@ static bool cp_parser_is_keyword
 | 
				
			||||||
static tree cp_parser_make_typename_type
 | 
					static tree cp_parser_make_typename_type
 | 
				
			||||||
  (cp_parser *, tree, tree, location_t location);
 | 
					  (cp_parser *, tree, tree, location_t location);
 | 
				
			||||||
static cp_declarator * cp_parser_make_indirect_declarator
 | 
					static cp_declarator * cp_parser_make_indirect_declarator
 | 
				
			||||||
 (enum tree_code, tree, cp_cv_quals, cp_declarator *, tree);
 | 
					  (enum tree_code, tree, cp_cv_quals, cp_declarator *, tree);
 | 
				
			||||||
 | 
					static bool cp_parser_compound_literal_p
 | 
				
			||||||
 | 
					  (cp_parser *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Returns nonzero if we are parsing tentatively.  */
 | 
					/* Returns nonzero if we are parsing tentatively.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5609,6 +5611,30 @@ cp_parser_qualifying_entity (cp_parser *parser,
 | 
				
			||||||
  return scope;
 | 
					  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.
 | 
					/* Parse a postfix-expression.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   postfix-expression:
 | 
					   postfix-expression:
 | 
				
			||||||
| 
						 | 
					@ -5917,25 +5943,12 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 | 
				
			||||||
	    && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
 | 
						    && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
 | 
				
			||||||
	  {
 | 
						  {
 | 
				
			||||||
	    tree initializer = NULL_TREE;
 | 
						    tree initializer = NULL_TREE;
 | 
				
			||||||
	    bool compound_literal_p;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    cp_parser_parse_tentatively (parser);
 | 
						    cp_parser_parse_tentatively (parser);
 | 
				
			||||||
	    /* Consume the `('.  */
 | 
					 | 
				
			||||||
	    cp_lexer_consume_token (parser->lexer);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    /* Avoid calling cp_parser_type_id pointlessly, see comment
 | 
						    /* Avoid calling cp_parser_type_id pointlessly, see comment
 | 
				
			||||||
	       in cp_parser_cast_expression about c++/29234.  */
 | 
						       in cp_parser_cast_expression about c++/29234.  */
 | 
				
			||||||
	    cp_lexer_save_tokens (parser->lexer);
 | 
						    if (!cp_parser_compound_literal_p (parser))
 | 
				
			||||||
 | 
					 | 
				
			||||||
	    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)
 | 
					 | 
				
			||||||
	      cp_parser_simulate_error (parser);
 | 
						      cp_parser_simulate_error (parser);
 | 
				
			||||||
	    else
 | 
						    else
 | 
				
			||||||
	      {
 | 
						      {
 | 
				
			||||||
| 
						 | 
					@ -23966,31 +23979,15 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword)
 | 
				
			||||||
  if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
 | 
					  if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      tree type = NULL_TREE;
 | 
					      tree type = NULL_TREE;
 | 
				
			||||||
      bool compound_literal_p;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /* We can't be sure yet whether we're looking at a type-id or an
 | 
					      /* We can't be sure yet whether we're looking at a type-id or an
 | 
				
			||||||
	 expression.  */
 | 
						 expression.  */
 | 
				
			||||||
      cp_parser_parse_tentatively (parser);
 | 
					      cp_parser_parse_tentatively (parser);
 | 
				
			||||||
      /* Consume the `('.  */
 | 
					 | 
				
			||||||
      cp_lexer_consume_token (parser->lexer);
 | 
					 | 
				
			||||||
      /* Note: as a GNU Extension, compound literals are considered
 | 
					      /* Note: as a GNU Extension, compound literals are considered
 | 
				
			||||||
	 postfix-expressions as they are in C99, so they are valid
 | 
						 postfix-expressions as they are in C99, so they are valid
 | 
				
			||||||
	 arguments to sizeof.  See comment in cp_parser_cast_expression
 | 
						 arguments to sizeof.  See comment in cp_parser_cast_expression
 | 
				
			||||||
	 for details.  */
 | 
						 for details.  */
 | 
				
			||||||
      cp_lexer_save_tokens (parser->lexer);
 | 
					      if (cp_parser_compound_literal_p (parser))
 | 
				
			||||||
      /* 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)
 | 
					 | 
				
			||||||
	cp_parser_simulate_error (parser);
 | 
						cp_parser_simulate_error (parser);
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue