This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/8665: explicit specialization of the member class template of a class template
- From: reichelt at igpm dot rwth-aachen dot de
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, jozef dot kosoru at pobox dot sk, nobody at gcc dot gnu dot org
- Date: 21 Nov 2002 22:00:59 -0000
- Subject: Re: c++/8665: explicit specialization of the member class template of a class template
- Reply-to: reichelt at igpm dot rwth-aachen dot de, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, jozef dot kosoru at pobox dot sk, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: explicit specialization of the member class template of a class template
State-Changed-From-To: open->closed
State-Changed-By: reichelt
State-Changed-When: Thu Nov 21 14:00:58 2002
State-Changed-Why:
Not a bug.
GCC is right: your code *is* ill-formed.
Actually, there are two bugs in your code. The first one is, that you try
to do the specialization inside the class (in the following example A is a
normal class instead of a templated one as in your example):
struct A
{
template <class X_> struct B {};
template <> struct B<char> {}; // wrong
};
template <> struct A::B<char> {}; // right
This is because of 14.7.3.2:
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.
Because you do the specialization in the class instead of the surrounding
namespace (which is the global one in this case) you get the message:
exptmpl.cpp:15: explicit specialization in non-namespace scope `struct A<T_>'
The second bug is, that you try to explicitly specialize B without
specializing A first - this is not allowed (see 14.7.3.18, especially
the last two lines of the example).
That's why you get the message:
exptmpl.cpp:15: enclosing class templates are not explicitly specialized
The rest of the error message is just fallout from the ill-formed
code above.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8665