The following code compiles in Visual C++ 2013 but not under G++ 4.8.2:
template<class T>
int MyFunc(T& t)
{
return static_cast<int>(CCodes::blah);
}
template<>
int MyFunc(float& t)
{
return 0;
}
int main() {
float f = 10.f;
return MyFunc(f);
}
Visual C++ seems to ignore the general template function because only the specialisation MyFunc<float>
is used. G++ parses the general function anyway and spots that the CCodes enumeration has not been defined.
Which is right? Or is this implementation-defined?
GCC is correct, and every other compiler besides MSVC will do the same thing.
This is a major bug, which actually appeared on one MSVC future roadmap. It was in the "distant future" category. They will have to rewrite their template engine to fix it.
There is a line of argument that diagnosis of an ill-formed template is optional, because it's really a template with no well-formed instantiation, and those are not required to be flagged. However,
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