【发布时间】:2013-12-07 03:11:31
【问题描述】:
我在使用 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;
}
产生如下错误(除了“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.
代码在 Dev-C++ 中使用 g++ 编译良好(嗯,它发出正确的错误消息并且不会使编译器崩溃)。
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;
}
您认为这值得向 Microsoft 报告吗?其他人可以重现这个吗? 也许尝试在 Visual Studio 2013 中看看是否仍然出现?
【问题讨论】:
-
此处可重现,Microsoft C/C++ 编译器 17.00.51106.1。
-
内部编译器错误始终是错误
-
如果你能重现这个问题,请点击这里的“我也能[重现这个bug]”:connect.microsoft.com/VisualStudio/feedback/details/800362/…
-
在 VS2013 (RC) 中,它不会以“错误 C2143:语法错误:缺少 ';'在“(”第 16 行第 1 列之前)。在添加缺少的
;之后,它会构建但会使编译器崩溃,并显示“错误 C1001:编译器中发生内部错误。”。 -
@namezero 啊,是的,你是对的,我错过了该代码的含义。几乎没有任何情况下访问冲突不是代码中的错误(所以在这种情况下,编译器本身)。
标签: c++ visual-c++ compiler-bug