I ran into a problem porting some code to MSVC, which puzzles me. As far as I know, the code should be legal, and Clang compiles it just fine.
I've narrowed it down to the following:
enum E {
x
};
template <typename T>
struct traits {
static const E val = x;
};
template <E e>
struct S {
S(){};
};
template <typename T>
S<traits<T>::val> foo(T t);
int main() {
char c = 0;
foo(c);
}
Note that after compilation, the code is expected to yield a linker error (I stripped away the definition of the function foo
to keep the sample minimal), but it should compile cleanly as far as I know.
However, MSVC gives me this error:
error C2893: Failed to specialize function template 'S::val> foo(T)'
So my question:
I've reproduced the problem on VC++ 2010 and 2012.
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