OSDN Git Service

PR c++/14497
authorgiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Jul 2004 00:13:41 +0000 (00:13 +0000)
committergiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Jul 2004 00:13:41 +0000 (00:13 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84983 138bc75d-0d04-0410-961f-82ee72b054a4

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 5883b7e..ddc3106 100644 (file)
@@ -1,5 +1,12 @@
 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
        * pt.c (determine_specialization): New parameter template_count.
        Disambiguate between member templates and member functions counting
index 3971b6d..b30bd57 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 b939e33..eb1a341 100644 (file)
@@ -1,5 +1,11 @@
 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
        * g++.dg/template/spec15.C: New test.
 
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;
-}
-
-