]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/19253 (bad error message / ICE for invalid template parameter)
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Tue, 15 Nov 2005 19:14:21 +0000 (19:14 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Tue, 15 Nov 2005 19:14:21 +0000 (19:14 +0000)
PR c++/19253
PR c++/22172
Backport from mainline:
2005-11-02  Mark Mitchell  <mark@codesourcery.com>

* parser.c (cp_parser_postfix_expression): Use
cp_parser_elaborated_type_specifier to handle typename-types in
functional casts.
(cp_parser_enclosed_argument_list): Skip ahead to the end of the
template argument list if the closing ">" is not found.

Backport from mainline:
2005-11-02  Mark Mitchell  <mark@codesourcery.com>

PR c++/19253
* g++.dg/parse/typename10.C: New test.

Backport from mainline:
2005-10-08  James A. Morrison  <phython@gcc.gnu.org>

PR c++/22172
* g++.dg/parse/crash30.C: New test.

From-SVN: r107037

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/crash30.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/typename10.C [new file with mode: 0644]

index beab029a9bb3a4fb851543a08d748b3f26be85b6..27bd947719117665f7163db8ff00acc3c6b372cd 100644 (file)
@@ -1,3 +1,16 @@
+2005-11-15  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/19253
+       PR c++/22172
+       Backport from mainline:
+       2005-11-02  Mark Mitchell  <mark@codesourcery.com>
+
+       * parser.c (cp_parser_postfix_expression): Use
+       cp_parser_elaborated_type_specifier to handle typename-types in
+       functional casts.
+       (cp_parser_enclosed_argument_list): Skip ahead to the end of the
+       template argument list if the closing ">" is not found.
+
 2005-11-14  Jason Merrill  <jason@redhat.com>
 
        PR c++/24580
index 03c9f589ce5bf25905c25756f5d9fbb7dc9924e8..70218f92f5ec6d58c7c6a3440a7c62bdcafd8061 100644 (file)
@@ -3552,52 +3552,13 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p)
       
     case RID_TYPENAME:
       {
-       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.  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
-          identifier.  */
-       cp_parser_parse_tentatively (parser);
-       /* Try a template-id.  */
-       id = cp_parser_template_id (parser, template_p,
-                                   /*check_dependency_p=*/true,
-                                   /*is_declaration=*/true);
-       /* 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.  */
-       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
-          functional cast is being performed.  */
-       else
-         type = make_typename_type (parser->scope, id, 
-                                    /*complain=*/1);
 
+       /* The syntax permitted here is the same permitted for an
+          elaborated-type-specifier.  */
+       type = cp_parser_elaborated_type_specifier (parser,
+                                                   /*is_friend=*/false,
+                                                   /*is_declaration=*/false);
        postfix_expression = cp_parser_functional_cast (parser, type);
       }
       break;
@@ -14776,8 +14737,8 @@ cp_parser_enclosed_template_argument_list (cp_parser* parser)
          cp_lexer_consume_token (parser->lexer);
        }
     }
-  else if (!cp_parser_require (parser, CPP_GREATER, "`>'"))
-    error ("missing `>' to terminate the template argument list");
+  else
+    cp_parser_skip_until_found (parser, CPP_GREATER, "`>'");
   /* The `>' token might be a greater-than operator again now.  */
   parser->greater_than_is_operator_p 
     = saved_greater_than_is_operator_p;
index b4e0a4009cc33935e181502aa5e9bddf9ed5dd63..b41dcceda451e396fb3949eb88f1cb0cbb8d6c7b 100644 (file)
@@ -1,3 +1,17 @@
+2005-11-15  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       Backport from mainline:
+       2005-11-02  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/19253
+       * g++.dg/parse/typename10.C: New test.
+
+       Backport from mainline:
+       2005-10-08  James A. Morrison  <phython@gcc.gnu.org>
+
+       PR c++/22172
+       * g++.dg/parse/crash30.C: New test.
+
 2005-11-10  Uros Bizjak  <uros@kss-loka.si>
 
         PR target/24315
diff --git a/gcc/testsuite/g++.dg/parse/crash30.C b/gcc/testsuite/g++.dg/parse/crash30.C
new file mode 100644 (file)
index 0000000..9b68535
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+namespace N { template<int> struct A { operator int() const; }; }
+namespace M { template<int> struct A {}; }
+namespace P { typedef int I; }
+
+template<typename> void foo()
+{
+  +typename N::A<0>();  // { dg-bogus "expected" }
+}
+
+template<typename> void bar()
+{
+  +typename M::A<0>;  // { dg-error "expected" }
+}
+
+template<typename T> void baz() {
+  typename P::I i;  // { dg-bogus "expected" }
+}
diff --git a/gcc/testsuite/g++.dg/parse/typename10.C b/gcc/testsuite/g++.dg/parse/typename10.C
new file mode 100644 (file)
index 0000000..759a3c9
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/19253
+
+namespace N { struct X; }
+
+template<typename> struct A
+{
+  A<typename N::X x> a; // { dg-error "invalid|declaration" }
+};