From 2b536806afcb297162fdc44e04cbf6f2c21e66aa Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 26 Oct 2007 17:53:56 +0000 Subject: [PATCH] re PR c++/33839 (ICE with decltype) 2007-10-26 Douglas Gregor PR c++/33839 * parser.c (cp_parser_decltype): Return ERROR_MARK_NODE if we don't see the leading '('. Only lookup names if we get an IDENTIFIER_NODE. 2007-10-26 Douglas Gregor * g++.dg/cpp0x/pr33839.C: New. From-SVN: r129656 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/parser.c | 20 +++++++++++--------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/pr33839.C | 8 ++++++++ 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr33839.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cabde879e8f..191836d5da6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-10-26 Douglas Gregor + + PR c++/33839 + * parser.c (cp_parser_decltype): Return ERROR_MARK_NODE if we + don't see the leading '('. Only lookup names if we get an + IDENTIFIER_NODE. + 2007-10-26 Jakub Jelinek PR c++/33744 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0b94375d358..2b73a85aaf7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8464,7 +8464,8 @@ cp_parser_decltype (cp_parser *parser) ++skip_evaluation; /* Parse the opening `('. */ - cp_parser_require (parser, CPP_OPEN_PAREN, "`('"); + if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('")) + return error_mark_node; /* First, try parsing an id-expression. */ cp_parser_parse_tentatively (parser); @@ -8482,14 +8483,15 @@ cp_parser_decltype (cp_parser *parser) cp_id_kind idk; const char *error_msg; - /* Lookup the name we got back from the id-expression. */ - expr = cp_parser_lookup_name (parser, expr, - none_type, - /*is_template=*/false, - /*is_namespace=*/false, - /*check_dependency=*/true, - /*ambiguous_decls=*/NULL); - + if (TREE_CODE (expr) == IDENTIFIER_NODE) + /* Lookup the name we got back from the id-expression. */ + expr = cp_parser_lookup_name (parser, expr, + none_type, + /*is_template=*/false, + /*is_namespace=*/false, + /*check_dependency=*/true, + /*ambiguous_decls=*/NULL); + if (expr && expr != error_mark_node && TREE_CODE (expr) != TEMPLATE_ID_EXPR diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0293ed0bdac..1257d0b1348 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2007-10-26 Douglas Gregor + + * g++.dg/cpp0x/pr33839.C: New. + 2007-10-26 Jakub Jelinek PR c++/33744 diff --git a/gcc/testsuite/g++.dg/cpp0x/pr33839.C b/gcc/testsuite/g++.dg/cpp0x/pr33839.C new file mode 100644 index 00000000000..4111d6ccfc0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr33839.C @@ -0,0 +1,8 @@ +// { dg-options -std=c++0x } +template struct A; + +void foo() +{ + __decltype A<0>; // { dg-error "invalid declarator" } + __decltype (A<0>); // { dg-error "must be an expression" } +} -- 2.30.2