我在使用Visual Stuido 2010 SP1,cl.exe版本16.0.40219.1编译一些模板代码时遇到了问题
下面的代码将导致编译器访问violate:
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;
}
它会生成以下错误(除了"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.
在使用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
编辑以下内容,但是,编译良好,没有访问冲突,所以这似乎与模板有关:
class A
{
A(){}
};
class B : public A
{
using A::A;
};
int main(int argc, char* argv[])
{
return 0;
}
你认为这值得向微软报告吗?其他人能复制这个吗?也许可以在Visual Studio 2013中尝试一下,看看它是否仍然会发生?
https://stackoverflow.com/questions/18765097
复制相似问题