diff options
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/parser.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/pr56239.C | 13 |
4 files changed, 32 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index afaec89..57912b9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,12 @@ 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) only if DECL_DISCRIMINATOR_SET_P (t) rather than just diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 72da561..402f384 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7091,8 +7091,9 @@ cp_parser_delete_expression (cp_parser* parser) 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: @@ -7133,6 +7134,12 @@ cp_parser_token_starts_cast_expression (cp_token *token) 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 (); @@ -7225,8 +7232,7 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p, 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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 67c5ccc..a7642dd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2013-02-07 Jakub Jelinek <jakub@redhat.com> + PR c++/56239 + * g++.dg/parse/pr56239.C: New test. + PR c++/56237 * g++.dg/abi/mangle61.C: New test. diff --git a/gcc/testsuite/g++.dg/parse/pr56239.C b/gcc/testsuite/g++.dg/parse/pr56239.C new file mode 100644 index 0000000..08f7f68 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/pr56239.C @@ -0,0 +1,13 @@ +// PR c++/56239 +// { dg-do compile } + +struct S +{ + int operator () () { return 0; } +}; + +int +main () +{ + return (S ()) (); +} |