This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] [PR14497] Remove leftover of the extension to specialize without template headers
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: <gcc-patches at gcc dot gnu dot org>
- Cc: "Jason Merrill" <jason at redhat dot com>
- Date: Fri, 18 Jun 2004 15:49:15 +0200
- Subject: [C++ PATCH] [PR14497] Remove leftover of the extension to specialize without template headers
Hello,
this patch removes a leftover from the extension with which we used to accept
specializations not introduced by the template header 'template <>'. This
extension was already removed for 3.4.0, but probably this part was forgotten.
Since I was at it, I slightly reorganized the error messages for invalid number
of template headers in check_explicit_specialization, and made them
fall-through to normal processing (to shut other error messages).
g++.old-deja/g++.robertl/eb118.C was testing for the extension, so I just
removed the file.
Tested on i686-pc-linux-gnu, OK for mainline?
Giovanni Bajo
cp/
PR c++/14497
* pt.c (check_explicit_specialization): Remove extension to accept
specializations without template headers. Fall-through to normal
processing.
testsuite/
PR c++/14497
* g++.dg/template/spec15.C: New test.
* g++.old-deja/g++.robertl/eb118.C: Remove.
Index: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.863
diff -c -3 -p -r1.863 pt.c
*** pt.c 16 Jun 2004 01:21:34 -0000 1.863
--- pt.c 18 Jun 2004 12:40:20 -0000
*************** check_explicit_specialization (tree decl
*** 1645,1653 ****
break;
case tsk_excessive_parms:
! error ("too many template parameter lists in declaration of `%D'",
! decl);
! return error_mark_node;
/* Fall through. */
case tsk_expl_spec:
--- 1689,1704 ----
break;
case tsk_excessive_parms:
! 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:
*************** check_explicit_specialization (tree decl
*** 1657,1688 ****
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)
--- 1708,1713 ----
// { 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" }
}