This in VS2010sp1 doesn’t compile (it does compile with gcc 4.6 though):
template<class T>
struct Upcast;
template<>
struct Upcast<signed char>
{
typedef signed short type;
};
template<>
struct Upcast<char>
{
typedef typename std::conditional<std::is_signed<char>::value,short, unsigned short>::type type;
};
int main()
{
Upcast<char>::type a;
return 0;
}
Error from VS:
Error 1 error C2899: typename cannot be used outside a template declaration
Which team is right? VS or gcc?
VS is right on C++03. GCC is right on C++0x.
Now it may be sensible for GCC to also allow this in C++03 mode (there are many things real compilers don’t diagnose in C++03 mode that are actually only valid in C++0x), and it may as-well sensible for VS to reject it in C++03 mode.
It doesn’t matter anymore whether or not a use of
typename QualifiedNamehappens in a template or not, in C++0x. That is, the following is perfectly legal for C++0x:In C++03,
typenamecould only be used inside of a template. And the explicit specialization in your code is not a template. There are notemplate<typename T ...>clauses (all parameters in your code are fixed).