Today, a friend of mine and I struggled a lot on a stupid mistake, and I make me wondered about how template parameters work in C++. Consider the following code, where I try to partially specialize a class attr<MyClass<I>> where I is an unsigned int, though MyClass expects an int parameter :
#include <iostream>
template<int I>
class MyClass
{
};
template<typename T>
struct attr;
template<unsigned int I>
struct attr<MyClass<I>>
{
};
int main(int argc, char *argv[])
{
attr<MyClass<1>> att;
return 0;
}
g++ fails with error message
main.cpp: In function ‘int main(int, char**)’:
main.cpp:20:22: erreur : aggregate ‘attr<MyClass<1> > att’ has incomplete type and cannot be defined
attr<MyClass<1>> att;
And clang compiles it (only a warning due to the fact that att is unused).
So I was wondering :
is there anything in the spec that would rule in favor of one or the other ?
could we say that
clangtemplate parameter's typing is weaker thang++'s ?