The following bit of code compiles in GCC 4.5.3 but does not compile in VS 2008 and 2010. Is this due to a VS compiler bug or does the standard forbid giving default function template argument values?
#include <cstdlib>
struct Bar
{
enum Group{ A , B , C };
};
struct Foo
{
template<typename T>
static void getSome( typename T::Group = T::A );
};
template<typename T>
void Foo::getSome( typename T::Group )
{
};
int main()
{
Foo::getSome<Bar>(); // Does not compile in VS 2008 & 2010 (compiles in gcc 4.5.3)
Foo::getSome<Bar>( Bar::C ); // Compiles in VS 2008 and gcc 4.5.3
return EXIT_SUCCESS;
}
Error message
prog.cpp(11) : error C2589: '::' : illegal token on right side of '::'
prog.cpp(11) : error C2059: syntax error : '::'
It is a MSVC bug.
The bug is in the handling of template functions with default parameters, as you probably guessed.
Their workaround is to supply all function parameters. (yuck)
Acknowledged here.