C++致命错误 C1001:编译器中发生内部错误

C++ fatal error C1001: An internal error has occurred in the compiler

本文关键字:内部 错误 编译器 致命错误 C1001 C++      更新时间:2023-10-16

在发布模式下编译时出现以下错误。

1>d:userseyalprojectscodeyallacoresrcrunboxwin32window.cpp : fatal error C1001: An internal error has occurred in the compiler.
1>         (compiler file 'f:ddvctoolscompilerutcsrcp2main.c', line 249)
1>          To work around this problem, try simplifying or changing the program near the locations listed above.
1>         Please choose the Technical Support command on the Visual C++
1>          Help menu, or open the Technical Support help file for more information
1>           link!RaiseException()+0x48
1>           link!CxxThrowException()+0x65
1>           link!std::_Xout_of_range()+0x1f
1>           link!InvokeCompilerPass()+0x1b4e2
1>           link!InvokeCompilerPass()+0x22efe
1>           link!InvokeCompilerPass()+0x2332e
1>           link!InvokeCompilerPass()+0x232f9
1>           link!InvokeCompilerPass()+0x233cb
1>           link!InvokeCompilerPass()+0x22b04
1>           link!InvokeCompilerPass()+0x22d86
1>           link!DllGetC2Telemetry()+0x115837
1>
1>     1>
1>LINK : fatal error LNK1257: code generation failed

我正在使用VS2015更新2 RC。

我不确定,但也许这是优化器中的错误?

导致它的代码如下:

窗口.h

class Window {
public:
    Window();
    ~Window();
    void show();
    void hide();
private:
    class NativeControl;
    std::unique_ptr<NativeControl> _window;
};

窗口.cpp

class Window::NativeControl : public NativeWindow {
public:
    NativeControl() : NativeWindow() { }
};
Window::Window()
    : _window(std::make_unique<Window::NativeControl>()) {
}
Window::~Window() {
}
void Window::show() 
{
    _window->show(WindowShowMode::Show);
}
void Window::hide()
{
    _window->show(WindowShowMode::Hide);
}

NativeWindow是任何操作系统的本机窗口。

以下是使用 GCC 5.1 编译的工作代码: https://ideone.com/4YvjRK

只是为了做一个笔记。

如果我删除继承并将其替换为这样的东西。

class Window::NativeControl {
public:
    void show(WindowShowMode showMode)
    {
    }
};

它会正常工作!

以下是使用 GCC 5.1 编译的相同代码,没有继承:https://ideone.com/Mu0A42

似乎导致这种行为的是NativeWindow的NativeControl派生。

重现它的步骤如下:

  1. 从 Window 类中删除 dtor 声明和定义。
  2. 尝试构建(而不是重建)。
  3. 编译器会抱怨并给你一堆错误。

1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\memory(1194):错误 C2338:无法删除不完整的类型 1> 1> 1>C:\程序文件 (x86)\Microsoft Visual Studio 14.0\VC\include\memory(1195):警告 C4150:删除指向不完整类型"Yalla::Window::NativeControl"的指针;未调用析构函数 1>
d:\Users\Eyal\Projects\Code\Yalla\core\src\runbox\include\window.h(13): 注意:请参阅"Yalla::Window::NativeControl"的声明 1>
窗口.cpp 1> 1>生成失败。

  1. 将 dtor 添加回 Window 类。
  2. 再次生成(不是重新生成)。
  3. 此时,编译器应报告以下错误"致命错误 C1001:编译器中发生内部错误"。

有趣的是,进行重建似乎可以解决问题!

我想要实现的基本上是在不同的文件中实现 NativeWindow,主要是为了简单起见,而不是关于可重用性。

我想与其在继承中这样做,这可能会混淆unique_ptr模板,我还可以通过组合并通过 getter 公开 NativeWindow 的实例,它可能会起作用,但问题是是否有更好的方法可以做到这一点?

我正在重新学习C++很长一段时间后我没有碰它,所以如果我正在做的一些事情没有意义,请告诉我!

更新:

C++标准说:

unique_ptr的模板参数 T 可能是不完整的类型。

我在Herb Sutter的博客中找到了一篇关于它的文章。

类似的错误

(编译器文件 'f:\dd\VCtools\Compiler\utc\SRC\P2\main.c',第 255 行)

已修复更改Properties->Linker->Optimization->Link Time Code Generation/LTCG:incremental/LTCG

工作室 2015 更新 3

我在

构建一个琐碎的C++命令行应用程序并使用Microsoft Visual Studio Community 2019 版本 16.6.2 时遇到了类似的致命错误。

将默认/LTCG:incremental更改为/LTCG project -> properties -> linker -> optimization以进行release配置解决了该问题。

补充一点,此错误是在最近的VS2019更新之一(不确定是哪个特定的更新)之后开始的。

我解决了这个问题以 64 位链接大库。Visual Studio 尝试使用默认(32 位链接)。

Configuration Properties -> Advanced -> Preferred Build Tool Architecture -> 64-bit (x64)

与编译器文件 p0io.c 相关的error C1001主要是由于启用"使用 Unicode UTF-8"支持全球语言的区域设置。您可以看到有关具体原因的链接。您可以单击

Time &Language -> Region-> Additional date, time, &regional settings-> Region-> Administrative->Change system locale

并关闭 UTF-8。