@@ -4527,7 +4527,7 @@ class token_pair
{
m_open_loc = cp_lexer_peek_token (parser->lexer)->location;
return cp_parser_require (parser, traits_t::open_token_type,
- traits_t::required_token_open);
+ traits_t::required_token_open);
}
/* Consume the next token from PARSER, recording its location as
@@ -4541,16 +4541,6 @@ class token_pair
return tok;
}
- /* Peek the next token from PARSER, recording its location as
- that of the opening token within the pair. */
-
- void peek_open (cp_parser *parser)
- {
- cp_token *tok = cp_lexer_peek_token (parser->lexer);
- gcc_assert (tok->type == traits_t::open_token_type);
- m_open_loc = tok->location;
- }
-
/* If the next token is the closing symbol for this pair, consume it
and return it.
Otherwise, issue an error, highlighting the location of the
@@ -4559,8 +4549,8 @@ class token_pair
cp_token *require_close (cp_parser *parser) const
{
return cp_parser_require (parser, traits_t::close_token_type,
- traits_t::required_token_close,
- m_open_loc);
+ traits_t::required_token_close,
+ m_open_loc);
}
private:
@@ -6443,9 +6433,6 @@ cp_parser_qualifying_entity (cp_parser *parser,
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.
@@ -6857,6 +6844,9 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
cp_parser_parse_tentatively (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
+
/* Avoid calling cp_parser_type_id pointlessly, see comment
in cp_parser_cast_expression about c++/29234. */
if (!cp_parser_compound_literal_p (parser))
@@ -6868,8 +6858,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
parser->in_type_id_in_expr_p = true;
type = cp_parser_type_id (parser);
parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
- /* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
}
/* If things aren't going well, there's no need to
@@ -27773,12 +27762,13 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword)
{
tree type = NULL_TREE;
- matching_parens parens;
- parens.peek_open (parser);
-
/* We can't be sure yet whether we're looking at a type-id or an
expression. */
cp_parser_parse_tentatively (parser);
+
+ matching_parens parens;
+ parens.consume_open (parser);
+
/* 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