I have a template and a specialization defined like this:
template<typename T>
struct SomeTemplate final
{
};
template<>
struct SomeTemplate<int> final
{
};
int main()
{
SomeTemplate<int> test; // <-- error
}
Compiling with Visual C++ 2012 gives me the following error:
error C2913: explicit specialization; 'SomeTemplate<T>' is not a specialization of a class template
with
[
T=int
]
It compiles fine and does the right thing when I remove
- the
finalspecifiers - the
template<>from the specialization
The first case makes some sense to me, as it may very well be that final does also restrict specialization of templates (instead of only inheritance). The second case seems a bit strange to me, as I thought this should be a syntax error.
Is this behavior correct?
I'm not sure weather it's a bug of Visual C++ 2012, your original code compiles fine with the newer version of VC++ here.
No, final specifier has nothing to do with template specialization.
And
Yes it should be a syntax error if you remove
template<>.