From: Kriang Lerdsuwanakij Date: Sat, 19 Mar 2005 12:26:36 +0000 (+0000) Subject: re PR c++/20333 (ICE on invalid code, typename outside of a template) X-Git-Tag: releases/gcc-3.4.4~145 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97486817945d73e2ffef66a598449d4c03ec021a;p=thirdparty%2Fgcc.git re PR c++/20333 (ICE on invalid code, typename outside of a template) PR c++/20333 * parser.c (cp_parser_postfix_expression) : Check the return value of cp_parser_nested_name_specifier. * g++.dg/template/crash36.C: New test. From-SVN: r96724 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 61e216c57354..6fd9b4b27ab2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2005-03-19 Kriang Lerdsuwanakij + + PR c++/20333 + * parser.c (cp_parser_postfix_expression) : + Check the return value of cp_parser_nested_name_specifier. + 2005-03-08 Mark Mitchell PR c++/20142 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8b1075f52ffa..d720d0f6e05c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3551,18 +3551,22 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p) bool template_p = false; tree id; tree type; + tree scope; /* Consume the `typename' token. */ cp_lexer_consume_token (parser->lexer); /* Look for the optional `::' operator. */ cp_parser_global_scope_opt (parser, /*current_scope_valid_p=*/false); - /* Look for the nested-name-specifier. */ - cp_parser_nested_name_specifier (parser, - /*typename_keyword_p=*/true, - /*check_dependency_p=*/true, - /*type_p=*/true, - /*is_declaration=*/true); + /* Look for the nested-name-specifier. In case of error here, + consume the trailing id to avoid subsequent error messages + for usual cases. */ + scope = cp_parser_nested_name_specifier (parser, + /*typename_keyword_p=*/true, + /*check_dependency_p=*/true, + /*type_p=*/true, + /*is_declaration=*/true); + /* Look for the optional `template' keyword. */ template_p = cp_parser_optional_template_keyword (parser); /* We don't know whether we're looking at a template-id or an @@ -3575,9 +3579,13 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p) /* If that didn't work, try an identifier. */ if (!cp_parser_parse_definitely (parser)) id = cp_parser_identifier (parser); + + /* Don't process id if nested name specifier is invalid. */ + if (scope == error_mark_node) + return error_mark_node; /* If we look up a template-id in a non-dependent qualifying scope, there's no need to create a dependent type. */ - if (TREE_CODE (id) == TYPE_DECL + else if (TREE_CODE (id) == TYPE_DECL && !dependent_type_p (parser->scope)) type = TREE_TYPE (id); /* Create a TYPENAME_TYPE to represent the type to which the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e6c3650bcaaf..bdd7e7241e1f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-03-19 Kriang Lerdsuwanakij + + PR c++/20333 + * g++.dg/template/crash36.C: New test. + 2005-03-17 Richard Sandiford * gcc.dg/torture/pr19683-1.c: New test.