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]

Re: static template specialization

[Get raw message]
Levente Farkas wrote:
> 
> hi,
> Is this code incorrect or it's just a gcc bug?
> ------------
> class A
> {
>   template<typename T>
>     static int get(T) { return 0; }
>   template<>
>     static int get(int) { return 1; }
>   template<>
>     static int get(double) { return 2; }
> };

Unfortunately, this is disallowed in 14.7.3, p2:

    An explicit specialization shall be declared in the namespace
    of which the template is a member, or, for member templates,
    in the namespace of which the enclosing class or enclosing class
    template is a member. An explicit specialization of a member
    function, member class or static data member of a class template
    shall be declared in the namespace of which the class template
    is a member. ...

Apparently, the restriction exists to make the feature easier to
implement, specifically in the case of explicit specialization of
member templates of class templates. It sure would be a nice thing
to have, though. Perhaps as a g++ extension until the restriction
is lifted from the standard?

Regards
Martin


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