nam*_*ero 18 c++ visual-c++ compiler-bug
我遇到了使用Visual Stuido 2010 SP1,cl.exe版本16.0.40219.1编译一些模板代码的问题
以下代码将导致编译器访问违规:
template<typename T>
class A
{
A(){}
};
template<typename T>
class B : public A<T>
{
using A::A(); // Compiler access violates
// **EDIT**
//using A<T>::A<T>; // Compiler succeeds
//using A<T>::A(); // Compiler reports error
};
int main(int argc, char* argv[])
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它会生成以下错误(除了"cl.exe已停止工作,C0000005异常):
1>d:\projects\cpptest\cpptest\cpptest.cpp(11): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1420)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
Run Code Online (Sandbox Code Playgroud)
在使用g ++的Dev-C++中,代码可以很好地编译(好吧,也就是说,它会发出正确的错误消息并且不会使编译器崩溃).
main.cpp:11: error: `template<class T> class A' used without template parameters
main.cpp:11: error: expected nested-name-specifier before "A"
main.cpp:11: error: using-declaration for non-member at class scope
main.cpp:11: error: expected `;' before '(' token
main.cpp:11: error: expected unqualified-id before ')' token
make.exe: *** [main.o] Error 1
Run Code Online (Sandbox Code Playgroud)
编辑 以下,编译正常,没有访问冲突,所以它似乎与模板有关:
class A
{
A(){}
};
class B : public A
{
using A::A;
};
int main(int argc, char* argv[])
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
您认为这值得向微软汇报吗?其他人可以重现这个吗?也许尝试在Visual Studio 2013中查看它是否仍然存在?
由于其他人可以在 Visual C++ 平台上重现此问题,因此我在Microsoft Connect上打开了一份错误报告作为“答案”。
另外,作为解决方法,以下语法有效:
using A<T>::A<T>;
Run Code Online (Sandbox Code Playgroud)