Backported from mainline
2013-02-07 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/56239
+ * parser.c (cp_parser_token_starts_cast_expression): Renamed to...
+ (cp_parser_tokens_start_cast_expression): ... this. Change parameter
+ to cp_parser *, call cp_lexer_peek_token first. For CPP_OPEN_PAREN,
+ return true only if 2nd token isn't CPP_CLOSE_PAREN.
+ (cp_parser_cast_expression): Adjust caller.
PR c++/56237
* decl.c (push_local_name): Look at DECL_DISCRIMINATOR (t)
otherwise. */
static bool
-cp_parser_token_starts_cast_expression (cp_token *token)
+cp_parser_tokens_start_cast_expression (cp_parser *parser)
{
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
switch (token->type)
{
case CPP_COMMA:
case CPP_EOF:
return false;
+ case CPP_OPEN_PAREN:
+ /* In ((type ()) () the last () isn't a valid cast-expression,
+ so the whole must be parsed as postfix-expression. */
+ return cp_lexer_peek_nth_token (parser->lexer, 2)->type
+ != CPP_CLOSE_PAREN;
+
/* '[' may start a primary-expression in obj-c++. */
case CPP_OPEN_SQUARE:
return c_dialect_objc ();
parenthesized ctor such as `(T ())' that looks like a cast to
function returning T. */
if (!cp_parser_error_occurred (parser)
- && cp_parser_token_starts_cast_expression (cp_lexer_peek_token
- (parser->lexer)))
+ && cp_parser_tokens_start_cast_expression (parser))
{
cp_parser_parse_definitely (parser);
expr = cp_parser_cast_expression (parser,