c语言编译器内部错误,C++致命错误C1001:编译器中发生内部错误
在發布模式下編譯時出現以下錯誤。
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。
我不確定,但也許這是優化器中的錯誤?
導致它的代碼如下所示:
在window.h
class Window {
public:
Window();
~Window();
void show();
void hide();
private:
class NativeControl;
std::unique_ptr _window;
};window.cpp
class Window::NativeControl : public NativeWindow {
public:
NativeControl() : NativeWindow() { }
};
Window::Window()
: _window(std::make_unique<: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。
重現它的步驟如下:
從Window類中刪除dtor聲明和定義。
嘗試構建(不重建)。
編譯器會抱怨并給你一堆錯誤。
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.
將dtor添加回Window類。
重新構建(不重建)。
此時,編譯器應該抱怨以下錯誤“致命錯誤C1001:編譯器發生內部錯誤。”
有趣的部分是做重建似乎解決了這個問題!
我想要實現的基本上是將NativeWindow的實際實現放在不同的文件中,主要是為了簡單起見,而不是關于可重用性。
我想這不是在繼承中做的,也許會讓unique_ptr模板混淆,我也可以通過組合來做到這一點,并通過getter公開NativeWindow的實例,它可能會工作,但問題是是否有更好的方法來做到這一點?
我在很長一段時間后重新學習C++,我沒有碰它,所以如果我所做的一些事情沒有意義,請告訴我!
更新:
C++標準說:
unique_ptr的模板參數T可能是一個不完整的類型。
我在Herb Sutter的blog上發現了一篇關于它的文章。
總結
以上是生活随笔為你收集整理的c语言编译器内部错误,C++致命错误C1001:编译器中发生内部错误的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言程序设计 计算个人所得税 浙大版,
- 下一篇: c语言 整形数组如果输入回车,数字数组