This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/57746] rejected valid specialization of member function of class template (I think)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57746

--- Comment #7 from Daniel KrÃgler <daniel.kruegler at googlemail dot com> ---
(In reply to Andy Lutomirski from comment #4)
> Daniel, I'm unconvinced that your interpretation is the intended one. 

Well, [temp.spec] p5 says more strongly that an explicit instantiation shall
only follow a declaration of an explicit specialization:

"For a given template and a given set of template-arguments,
â an explicit instantiation definition shall appear at most once in a program,
â an explicit specialization shall be defined at most once in a program
(according to 3.2), and
â both an explicit instantiation and a declaration of an explicit
specialization shall not appear in a program unless the explicit instantiation
follows a declaration of the explicit specialization.
An implementation is not required to diagnose a violation of this rule."

This is in agreement of my interpretation of [temp.explicit] p4.

> Regardless, the interesting case is:
> 
> template<typename T>
> struct X
> {
>   static int val;
>   static void func();
> };
> 
> // optionally: extern template struct X<int>;
> 
> void something()
> {
>   X<int>::func();
> }
> 
> in one file and
> 
> struct X
> {
>   static int val;
>   static void func();
> };
> 
> template<> void X<int>::func() {}

This code is not supported by the standard:

a) If the explicit instantiation declaration is provided, this violates above
quoted bullet 3 (you missed to declare the explicit specialization before). In
addition to that [temp.explicit] p11 requires the existence of an explicit
instantiation definition of X<int>::func():

"An entity that is the subject of an explicit instantiation declaration and
that is also used in a way that would otherwise cause an implicit instantiation
(14.7.1) in the translation unit shall be the subject of an explicit
instantiation definition somewhere in the program; otherwise the program is
ill-formed, no diagnostic required."

b) If the explicit instantiation declaration is *not* provided, X<int>::func()
is implicitly instantiated, but you provide an explicit instantiation instead.
This violates [temp.spec] p4:

"An instantiated template specialization can be either implicitly instantiated
(14.7.1) for a given argument list or be explicitly instantiated (14.7.2). A
specialization is a class, function, or class member that is either
instantiated or explicitly specialized (14.7.3)." 

More strongly, [temp.expl.spec] p6 says:

"If a template, a member template or a member of a class template is explicitly
specialized then that specialization shall be declared before the first use of
that specialization that would cause an implicit instantiation to take place,
in every translation unit in which such a use occurs; no diagnostic is
required."

You don't have the explicit specialization of  X<int>::func() declared in the
first TU that implicitly instantiates this member.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]