]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/22153 (ICE on invalid template specialization)
authorJosh Conner <jconner@apple.com>
Fri, 28 Oct 2005 18:47:28 +0000 (18:47 +0000)
committerJosh Conner <jconner@gcc.gnu.org>
Fri, 28 Oct 2005 18:47:28 +0000 (18:47 +0000)
Merged from mainline change #105944:

PR c++/22153
* cp/parser.c (cp_parser_member_declaration): Detect and handle
a template specialization.
* testsuite/g++.dg/template/crash38.C: New test.
* testsuite/g++.dg/parse/explicit1.C: Change expected errors.

From-SVN: r105946

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

index dee049b315e1a7fed18c072443554a1794249511..4f7b178d4185574d63086d09411cb1168725358d 100644 (file)
@@ -1,3 +1,9 @@
+2005-10-28  Josh Conner  <jconner@apple.com>
+
+       PR c++/22153
+       * parser.c (cp_parser_member_declaration): Detect and handle
+       a template specialization.
+
 2005-10-20  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/22508
index 198fe79f3845e47f6518665a1765f0341ed80976..03c9f589ce5bf25905c25756f5d9fbb7dc9924e8 100644 (file)
@@ -12518,8 +12518,13 @@ cp_parser_member_declaration (cp_parser* parser)
   /* Check for a template-declaration.  */
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
     {
-      /* Parse the template-declaration.  */
-      cp_parser_template_declaration (parser, /*member_p=*/true);
+      /* An explicit specialization here is an error condition, and we
+        expect the specialization handler to detect and report this.  */
+      if (cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_LESS
+         && cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_GREATER)
+       cp_parser_explicit_specialization (parser);
+      else
+       cp_parser_template_declaration (parser, /*member_p=*/true);
 
       return;
     }
index 7b6905a9290e3aff270a24e759910cf60a07beb0..3676223f86b3524d880802097e7dc5ba7b06e024 100644 (file)
@@ -1,3 +1,9 @@
+2005-10-28  Josh Conner  <jconner@apple.com>
+
+       PR c++/22153
+       * g++.dg/template/crash38.C: New test.
+       * g++.dg/parse/explicit1.C: Change expected errors.
+
 2005-10-21  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.c-torture/execute/20051021-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/crash38.C b/gcc/testsuite/g++.dg/crash38.C
new file mode 100644 (file)
index 0000000..d36ced4
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-do compile }
+
+// PR c++/22153
+
+template<int> void foo();
+
+template<int> struct A
+{
+    template<> friend void foo<0>(); // { dg-error "" }
+};
index ced2adc3dc091006a786e87ee014d4269d9d99b7..35358749e1d082e9e85d913627497ecaf9ac20fe 100644 (file)
@@ -7,5 +7,5 @@
 
 struct foo { 
         template<typename T> void bar (T &t) {}
-        template<> void bar<double>(double &t) {} // { dg-error "explicit|non-namespace|member" }
+        template<> void bar<double>(double &t) {} // { dg-error "non-namespace|template|function" }
 };