]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/20333 (ICE on invalid code, typename outside of a template)
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Sat, 19 Mar 2005 12:26:36 +0000 (12:26 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Sat, 19 Mar 2005 12:26:36 +0000 (12:26 +0000)
PR c++/20333
* parser.c (cp_parser_postfix_expression) <case RID_TYPENAME>:
Check the return value of cp_parser_nested_name_specifier.

* g++.dg/template/crash36.C: New test.

From-SVN: r96724

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog

index 61e216c5735456d454ddb2a9bb48329a97f740c4..6fd9b4b27ab2d667ce4681a2055772d6a2b3206a 100644 (file)
@@ -1,3 +1,9 @@
+2005-03-19  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/20333
+       * parser.c (cp_parser_postfix_expression) <case RID_TYPENAME>:
+       Check the return value of cp_parser_nested_name_specifier.
+
 2005-03-08  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/20142
index 8b1075f52ffa4e1bfd2250b3ce9b00c7586fd1ae..d720d0f6e05ce0cf2c20866d9496258f6e5b1111 100644 (file)
@@ -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
index e6c3650bcaaf03d265df400a058f4cf1692943f6..bdd7e7241e1fc7edd706f32a1163e387fccba175 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-19  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/20333
+       * g++.dg/template/crash36.C: New test.
+
 2005-03-17  Richard Sandiford  <rsandifo@redhat.com>
 
        * gcc.dg/torture/pr19683-1.c: New test.