re PR c++/29730 (ICE on invalid declaration of template member)
authorMark Mitchell <mark@codesourcery.com>
Wed, 6 Dec 2006 22:54:51 +0000 (22:54 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 6 Dec 2006 22:54:51 +0000 (22:54 +0000)
PR c++/29730
* parser.c (cp_parser_init_declarator): Reject initialization of
functions.
PR c++/29730
* g++.dg/template/crash64.C: New test.
* g++.dg/parse/crash27.C: Adjust error markers.

From-SVN: r119601

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

index 9e63aca5e8a1cf93ee6ac848fc9a9a5294f173da..07e6b63aa38000803656fdac9000c92dfa55b1c7 100644 (file)
@@ -1,3 +1,9 @@
+2006-12-06  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/29730
+       * parser.c (cp_parser_init_declarator): Reject initialization of
+       functions.
+
 2006-12-05  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/29729
index 82ee8873355adace8ac39de8932f21d53fce9bfe..cdb60f646237d76765f3802a4e07fb7b3daab4ef 100644 (file)
@@ -11311,9 +11311,23 @@ cp_parser_init_declarator (cp_parser* parser,
   is_non_constant_init = true;
   if (is_initialized)
     {
-      if (function_declarator_p (declarator)
-         && initialization_kind == CPP_EQ)
-       initializer = cp_parser_pure_specifier (parser);
+      if (function_declarator_p (declarator))
+       {
+          if (initialization_kind == CPP_EQ)
+            initializer = cp_parser_pure_specifier (parser);
+          else
+            {
+              /* If the declaration was erroneous, we don't really
+                 know what the user intended, so just silently
+                 consume the initializer.  */
+              if (decl != error_mark_node)
+                error ("initializer provided for function");
+              cp_parser_skip_to_closing_parenthesis (parser,
+                                                     /*recovering=*/true,
+                                                     /*or_comma=*/false,
+                                                     /*consume_paren=*/true);
+            }
+       }
       else
        initializer = cp_parser_initializer (parser,
                                             &is_parenthesized_init,
index 58837bc40ac72b2bc526d8666b1d30906a634e4b..79f1decd5e394f67392005aadbea74a8dfb9bf31 100644 (file)
@@ -1,3 +1,9 @@
+2006-12-06  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/29730
+       * g++.dg/template/crash64.C: New test.
+       * g++.dg/parse/crash27.C: Adjust error markers.
+
 2006-12-06  Thomas Koenig  <Thomas.Koenig@online.de>
 
        PR libfortran/30009
index 1a13f818f11d08e1f8f8a5b7d8276a2ea828e911..069436666d3bc44c0ac15cbfdbf77574aff6bf04 100644 (file)
@@ -3,6 +3,3 @@
 void Dispatcher()
         (__builtin_offsetof (ArgsType, largeMsgLen))
        /* { dg-error "function " "function" { target *-*-* } 4 } */
-       /* { dg-error "expected type" "expected 1" { target *-*-* } 4 } */
-       /* { dg-error "expected `,' before" "expected 2" { target *-*-* } 4 } */
-       /* { dg-error "expected `\\\)" "expected 3" { target *-*-* } 4 } */
diff --git a/gcc/testsuite/g++.dg/template/crash64.C b/gcc/testsuite/g++.dg/template/crash64.C
new file mode 100644 (file)
index 0000000..750e3da
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/29730
+
+struct A
+{
+  template<int> void foo()(0); // { dg-error "initializer" } 
+};