static tree cp_parser_make_typename_type
(cp_parser *, tree, tree, location_t location);
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. */
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:
&& 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
{
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
{