This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix PR c++/33839 (decltype ICE) (committed)
- From: "Doug Gregor" <doug dot gregor at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 26 Oct 2007 13:55:50 -0400
- Subject: [C++ PATCH] Fix PR c++/33839 (decltype ICE) (committed)
I've committed the attached trivial patch, which makes the parsing of
decltype a bit more robust against errors and fixes PR c++/33839.
- Doug
2007-10-26 Douglas Gregor <doug.gregor@gmail.com>
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 <doug.gregor@gmail.com>
* g++.dg/cpp0x/pr33839.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 129655)
+++ cp/parser.c (working copy)
@@ -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
Index: testsuite/g++.dg/cpp0x/pr33839.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr33839.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr33839.C (revision 0)
@@ -0,0 +1,8 @@
+// { dg-options -std=c++0x }
+template<int> struct A;
+
+void foo()
+{
+ __decltype A<0>; // { dg-error "invalid declarator" }
+ __decltype (A<0>); // { dg-error "must be an expression" }
+}