From f03adc6beee43a29d323390c019de535cc160f02 Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Wed, 21 Jul 2004 00:13:41 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 7 ++++ gcc/cp/pt.c | 39 +++++------------- gcc/testsuite/ChangeLog | 6 +++ gcc/testsuite/g++.dg/template/spec16.C | 11 +++++ .../g++.old-deja/g++.robertl/eb118.C | 40 ------------------- 5 files changed, 34 insertions(+), 69 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/spec16.C delete mode 100644 gcc/testsuite/g++.old-deja/g++.robertl/eb118.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5883b7e26de..ddc31069616 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2004-07-21 Giovanni Bajo + + 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 PR c++/509 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 struct S { void f(); }; - void S::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,3 +1,9 @@ +2004-07-21 Giovanni Bajo + + PR c++/14497 + * g++.dg/template/spec16.C: New test. + * g++.old-deja/g++.robertl/eb118.C: Remove. + 2004-07-21 Giovanni Bajo 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 index 00000000000..c5bd5a95426 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/spec16.C @@ -0,0 +1,11 @@ +// { dg-do compile } +// Contributed by Giovanni Bajo +// PR c++/14497: Reject specialization without template headers + +template +struct A { + template 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 -#include - -template -class A { -public: - void test (); -}; - -template -void -A::test(){ - std::cerr << "test for " << typeid(*this).name() << std::endl; -} -// Specialization declaration -template <> -void -A::test(); - -// Specialization definition -void -A::test(){ - std::cerr << "specialization for " << typeid(*this).name() << std::endl; -} - - -int -main(){ - A ai; - A ad; - ai.test(); - ad.test(); - return 0; -} - - -- 2.30.2