Har*_*aff 14 c++ enums templates template-specialization visual-c++
我正在使用Microsoft Visual Studio 2019编译器(cl.exe),它拒绝了Clang和GCC接受的一些与使用枚举作为模板参数有关的代码,其中模板专门用于特定的枚举值。
enum Foo {
Bar,
Baz
};
template<enum Foo = Bar> class Clazz {
};
template<> class Clazz<Baz> {
};
Run Code Online (Sandbox Code Playgroud)
VC ++编译器报告有关模板专业化的几个错误:
<source>(10): error C2440: 'specialization': cannot convert from 'Foo' to 'Foo'
<source>(10): note: Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
Run Code Online (Sandbox Code Playgroud)
Clang和GCC均接受此代码,没有错误。这是VC ++的错误吗?
用“ int”代替模板声明中的“ enum Foo”会导致错误消失。但是,这不是可接受的答案,因为我正在尝试将大型代码库移植到VC ++。