gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:45:17 26 4
gpt4 key购买 nike

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

1>d:\users\eyal\projects\code\yalla\core\src\runbox\win32\window.cpp : fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.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 Update 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 是任何操作系统的 native 窗口。

这是使用 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): error C2338: can't delete an incomplete type 1> 1> 1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\memory(1195): warning C4150: deletion of pointer to incomplete type 'Yalla::Window::NativeControl'; no destructor called 1>
d:\Users\Eyal\Projects\Code\Yalla\core\src\runbox\include\window.h(13): note: see declaration of 'Yalla::Window::NativeControl' 1>
window.cpp 1> 1>Build FAILED.

  1. 将 dtor 添加回 Window 类。
  2. 再次构建(不是重建)。
  3. 此时,编译器应报错以下错误“ fatal error C1001:编译器发生内部错误。”

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

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

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

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

更新:

C++ 标准说:

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

我在 Herb Sutter 的 blog 中找到了一篇关于它的帖子.

最佳答案

类似的错误

(编译器文件“f:\dd\vctools\compiler\utc\src\p2\main.c”,第 255 行)

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

Studio 2015 更新 3

关于C++ fatal error C1001 : An internal error has occurred in the compiler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36005206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com