namespace A{
namespace B{
template<typename T>
struct Test{
};
}
using namespace B;
template<>
struct Test<int>{}; //#1
}
int main(){
}
Consider the above code, GCC
complains such code is ill-formed and Clang
consider such code is well-formed. The outcome is here. At #1
, it's an explicit specialization declaration for class template Test
. According to this rule:
temp.expl.spec#2
An explicit specialization may be declared in any scope in which the corresponding primary template may be defined.
The primary template Test
can be defined outside namespace B
, as long as it obeys the following rule:
namespace.memdef#2
Members of a named namespace can also be defined outside that namespace by explicit qualification ([namespace.qual]) of the name being defined, provided that the entity being defined was already declared in the namespace and the definition appears after the point of declaration in a namespace that encloses the declaration's namespace.
That is we may define the primary template Test
like this:
namespace A{
namespace B{
template<typename T>
struct Test;
}
template<typename T>
struct B::Test{ // Test is explicit qualified by B
};
}
So, we're permitted to define explicit specialization at such point. However It's unclear that It is necessary to declare such explicit specialization by using qualified-id? However an additional rule is here:
temp.expl.spec#8
A template explicit specialization is in the scope of the namespace in which the template was defined.
So Clang
is wrong? How to interpret such case.