I am attempting to more fully grasp template syntax and semantics by imagining arcane constructs. I believe that the following syntax is not allowed by the C++11 standard:
template <typename T>
class A
{...};
// phony "specialization"
template <typename T>
class A<int>
{...};
However, I cannot find in the C++11 standard where this syntax is disallowed.
Am I correct that the syntax shown is disallowed by the C++11 standard? If so, where can it be found that the syntax is disallowed?
I'm quite surprised that there is no explicit statement in 14.5.5 [temp.class.spec] saying that all template parameters of a class template partial specialization must be used in the template-argument-list. That would make template<class T> class A<int>
invalid because T
is not used in the template-argument-list <int>
.
I think your phony specialization is only implicitly invalid due to the fact that you can never match it, so it can never be used. If you instantiate A<int>
then that matches the primary template. It can't match your specialization, because that has an additional template parameter, T
, which cannot be deduced (you suggest it could be provided by saying A<int><double>
but that is not valid C++ syntax, so doesn't help).
I've asked the standards committee for clarification why your phony specialization is invalid (obviously it is, but I can't see where it says so).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With