以下代码在 MinGW-gcc-4.8.2 g++ test.cpp -std=c++11
下编译良好:
// test.cpp
#include <iostream>
class Test
{
public:
int a[10] = {};
};
int main()
{
Test c;
std::cout << c.a[0];
return 0;
}
但是,当我将 msvc2013 与 cl test.cpp/EHsc
一起使用时,它给了我(抱歉,我没有英文版本,但您可以从错误编号中看出。):
test.cpp
test.cpp(6) : fatal error C1001: 编译器中发生内部错误。
(编译器文件“f:\dd\vctools\compiler\cxxfe\sl\p1\c\convert.cpp”,第 9608 行)
要解决此问题,请尝试简化或更改上面所列位置附近的程序。
请选择 Visual C++
“帮助”菜单上的“技术支持”命令,或打开技术支持帮助文件来获得详细信息。
最佳答案
正如在 Microsoft Developers Network 上所说的那样, 由于编译/构建优化而出现此消息,因此您可以尝试删除此优化。
The compiler cannot generate correct code for a construct, probably due to the combination of an expression and an optimization option. Try removing one or more optimization options and recompiling the function containing the line indicated in the error message.
You can probably fix the problem by removing one or more optimization options. To determine which option is at fault, remove options one at a time and recompile until the error message goes away. The options most commonly responsible are /Og, /Oi, and /Oa. Once you determine which option is responsible, you can disable it using the optimize pragma around the function where the error occurs and continue to use the option for the rest of the module.
正如他们所说 here , 您可以使用 /P
开关来获取有关编译器内部错误的更多信息。
关于使用 MSVC 2013 的 C++11 类内初始化器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22169424/