summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>2004-07-21 00:13:41 +0000
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>2004-07-21 00:13:41 +0000
commitf03adc6beee43a29d323390c019de535cc160f02 (patch)
treeab6927d50b5ba33b98710d1bbf22759f6b059905
parent5fe7b6549e1d588e3b0ae4015d61080bac3dbf37 (diff)
downloadgcc-f03adc6beee43a29d323390c019de535cc160f02.tar.gz
re PR c++/14497 (Accepts invalid specialization of member template missing "template<>")
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
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/pt.c39
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/template/spec16.C11
-rw-r--r--gcc/testsuite/g++.old-deja/g++.robertl/eb118.C40
5 files changed, 34 insertions, 69 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5883b7e26de..ddc31069616 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3971b6d37d2..b30bd5772b8 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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 "
+ "`template <>'", decl);
/* 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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b939e330a34..eb1a3410ea5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 00000000000..c5bd5a95426
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/spec16.C
@@ -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
index 723e8533346..00000000000
--- a/gcc/testsuite/g++.old-deja/g++.robertl/eb118.C
+++ /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;
-}
-
-