使用 MSVC 2013 的 C++11 类内初始化器

标签 c++ visual-c++ gcc c++11

以下代码在 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/

相关文章:

c++ - 在 C++ 中将大型文本文件快速读取为一维结构

c++ - Visual C++ 运行时对象销毁顺序

c++ - GCC - 具有相同名称的不同类的错误

c++ - 在 C++ 中读取 pcap 文件

c++ - 系统托盘上下文菜单不会消失

c++ - VC++ 使用 fp :fast causes wrong (not just inaccurate) results - is this a compiler bug?

gcc - 在制作 DLL 时让 ld 忽略 undefined reference

c++ - 在不同优化级别访问 gcc/g++ 中的局部变量和全局变量的速度

c++ - Visual Studio native 单元测试 : Debug/console output?

c++ - 如何在mfc中对日期和时间进行排序?