re PR c++/14497 (Accepts invalid specialization of member template missing "template<>")
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>
Wed, 21 Jul 2004 00:13:41 +0000 (00:13 +0000)
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>
Wed, 21 Jul 2004 00:13:41 +0000 (00:13 +0000)
PR c++/14497
* pt.c (check_explicit_specialization): Remove extension to accept
specializations without template headers. Fall-through to normal
processing.

PR c++/14497
* g++.dg/template/spec16.C: New test.
* g++.old-deja/g++.robertl/eb118.C: Remove.

From-SVN: r84983

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/spec16.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.robertl/eb118.C [deleted file]

index 5883b7e26deed87065665e3e15f2b94838dde228..ddc310696167b0c3c94aa70dac8cd84f38f11d10 100644 (file)
@@ -1,3 +1,10 @@
+2004-07-21  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/14497
+       * pt.c (check_explicit_specialization): Remove extension to accept
+       specializations without template headers. Fall-through to normal
+       processing.
+
 2004-07-21  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
 
        PR c++/509
index 3971b6d37d2b89c0d29d94055550ce5dbf9972da..b30bd5772b83e01812132c6e3dacb6e4eeebf08b 100644 (file)
@@ -1688,9 +1688,16 @@ check_explicit_specialization (tree declarator,
       break;
 
     case tsk_excessive_parms:
-      error ("too many template parameter lists in declaration of `%D'", 
-               decl);
-      return error_mark_node;
+    case tsk_insufficient_parms:
+      if (tsk == tsk_excessive_parms)
+        error ("too many template parameter lists in declaration of `%D'",
+              decl);
+      else if (template_header_count)
+       error("too few template parameter lists in declaration of `%D'",
+             decl);
+      else
+       error("explicit specialization of `%D' must be introduced by "\r
+             "`template <>'", decl);\r
 
       /* Fall through.  */
     case tsk_expl_spec:
@@ -1700,32 +1707,6 @@ check_explicit_specialization (tree declarator,
       else
        specialization = 1;
       break;
-     
-    case tsk_insufficient_parms:
-      if (template_header_count)
-       {
-         error("too few template parameter lists in declaration of `%D'", 
-                  decl);
-         return decl;
-       }
-      else if (ctype != NULL_TREE
-              && !TYPE_BEING_DEFINED (ctype)
-              && CLASSTYPE_TEMPLATE_INSTANTIATION (ctype)
-              && !is_friend)
-       {
-         /* For backwards compatibility, we accept:
-
-              template <class T> struct S { void f(); };
-              void S<int>::f() {} // Missing template <>
-
-            That used to be valid C++.  */
-         if (pedantic)
-           pedwarn
-             ("explicit specialization not preceded by `template <>'");
-         specialization = 1;
-         SET_DECL_TEMPLATE_SPECIALIZATION (decl);
-       }
-      break;
 
     case tsk_template:
       if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR)
index b939e330a34ac8d68d86947bae1ba324ab245f1e..eb1a3410ea5a8162e33f94ae240fe297f2e07baf 100644 (file)
@@ -1,3 +1,9 @@
+2004-07-21  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/14497
+       * g++.dg/template/spec16.C: New test.
+       * g++.old-deja/g++.robertl/eb118.C: Remove.
+
 2004-07-21  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
 
        PR c++/509
diff --git a/gcc/testsuite/g++.dg/template/spec16.C b/gcc/testsuite/g++.dg/template/spec16.C
new file mode 100644 (file)
index 0000000..c5bd5a9
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// Contributed by Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
+// PR c++/14497: Reject specialization without template headers
+
+template <int N>  
+struct A { 
+  template<int M> void B () ; 
+}; 
+
+void A<0>::B<0>() {    // { dg-error "explicit specialization" }
+} 
diff --git a/gcc/testsuite/g++.old-deja/g++.robertl/eb118.C b/gcc/testsuite/g++.old-deja/g++.robertl/eb118.C
deleted file mode 100644 (file)
index 723e853..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-// { dg-do run  }
-// { dg-options "" }
-// Test for obsolete specialization syntax.  Turn off -pedantic.
-
-#include <iostream>
-#include <typeinfo>
-
-template <typename T>
-class A {
-public:
-  void test ();
-};
-
-template <typename T>
-void
-A<T>::test(){
-  std::cerr << "test for " << typeid(*this).name() << std::endl;
-}
-// Specialization declaration
-template <> 
-void                           
-A<double>::test();
-
-// Specialization definition
-void
-A<double>::test(){
-  std::cerr << "specialization for " << typeid(*this).name() << std::endl;
-}
-
-
-int
-main(){
-  A<int> ai;
-  A<double> ad;
-  ai.test();
-  ad.test();
-  return 0;
-}
-
-