7

I'm getting the following error when compiling in release mode.

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

I'm using VS2015 Update 2 RC.

I'm not sure but maybe it's a bug in the optimizer?

The code that causes it is as follow:

window.h

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

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 is the native Window of whatever OS.

Here is a working code compiled with GCC 5.1: https://ideone.com/4YvjRK

Just to make a note.

If I'll remove the inheritance and replace it with something like this.

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

It will work fine!

Here is the same code compiled with GCC 5.1 with no inheritance: https://ideone.com/Mu0A42

What seems to cause this behaviour is the derivation of NativeControl from NativeWindow.

The steps to reproduce it as as follow:

  1. Remove the dtor declaration and definitions from the Window class.
  2. Try to Build (not Rebuild).
  3. The compiler will complain and give you bunch of errors.

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. Add back the dtor to the Window class.
  2. Build again (not Rebuild).
  3. At this point the compiler should complain with the following error "fatal error C1001: An internal error has occurred in the compiler."

The interesting part is that doing rebuild seems to fix the problem!

What I want to achieve is basically have the actual implementation of NativeWindow in a different file, mostly for simplicity and not so much about reusability.

I guess that instead of doing that in inheritance that maybe confuses the unique_ptr template I can also do that through composition and expose the instance of NativeWindow through a getter and it might work but the question is whether there are better ways to do it?

I'm relearning C++ after a very long time I didn't touch it so if some of the things I'm doing don't make sense, please tell me about it!

Update:

The C++ standard says:

The template parameter T of unique_ptr may be an incomplete type.

I found a post about it in Herb Sutter's blog.

iam3yal
  • 2,188
  • 4
  • 35
  • 44
  • Can you elaborate? like I said I'm relearning C++, haven't touch this for 10 years or so :D – iam3yal Mar 15 '16 at 07:48
  • 1
    `NativeControl` is incomplete type in `std::unique_ptr`. Pointer doesn't know how destroy pointer of incomplete type. You should place complete declaration of `NativeControl` in `window.h` – nikniknik2016 Mar 15 '16 at 07:48
  • @ nikniknik2016 so how come it works pretty well when I'm not deriving from anything? I mean if I'll copy the implementation from NativeWindow and paste it, then remove the inheritance it will work fine. – iam3yal Mar 15 '16 at 07:51
  • Updated my post with a note about it. – iam3yal Mar 15 '16 at 07:58
  • What is Yalla? Does it work if you move NativeControl in global space? – zdf Mar 15 '16 at 08:00
  • @ZDF I can try that! :) – iam3yal Mar 15 '16 at 08:12
  • 2
    ICEs are always compiler bugs. There's nothing wrong with the `unique_ptr` usage. – T.C. Mar 15 '16 at 08:59
  • 2
    Clearly this is a compiler problem (`C1001`). Go to Microsoft Connect and report it. They will ask for code. Meanwhile you have to find an workaround. (I assume `Yalla` is a namespace). Regarding the incomplete definition of `NativeControl`: it should work. – zdf Mar 15 '16 at 09:02
  • I think the underlying problem is the forward declaration of NativeWindow within Window. That means the type is not even declared. You can use a *naked* pointer for a pimpl but you can't manage it in a smart pointer. A smart pointer needs to access the destructor but the compiler cannot tell if such a destructor exists. As others have said, the error is a compiler bug. – Steve Kidd Mar 15 '16 at 09:03
  • Thank you all, I'll definitely report it! – iam3yal Mar 15 '16 at 09:04
  • @SteveKidd It works on my compiler. – zdf Mar 15 '16 at 09:04
  • @ZDF Think I jumped in without engaging my brain. I didn't see the NativeWindow declaration in window.cpp. Sorry!! – Steve Kidd Mar 15 '16 at 09:09
  • 1
    One more thing: my compiler's version is `14.0.24720.00 Update 1`, you have a `Release Candidate` version, not a real release. In other words, you might be luckier with `Update 1`. – zdf Mar 15 '16 at 09:12
  • @SteveKidd Do you mean NativeControl within window? because in the header there's nothing about NativeWindow, besides, I don't know but it seems like it's valid and it should work, here is a link where it works just fine with GCC 5.1 https://ideone.com/4YvjRK – iam3yal Mar 15 '16 at 09:14
  • @EyalSolnik As I said above, I was confusing myself. The code indeed does look fine. Just having a bad day. My mention of NativeWindow was me thinking that it must be declared before the std::unique_ptr constructor and destructor are instantiated - which while true, is not relevant. Apologies again. – Steve Kidd Mar 15 '16 at 20:16
  • @SteveKidd no problem mate! thanks anyway. :) – iam3yal Mar 15 '16 at 22:09

4 Answers4

2

similar error with

(compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 255)

was fixed changing Properties->Linker->Optimization->Link Time Code Generation from /LTCG:incremental to /LTCG

Studio 2015 Update 3

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
Anton
  • 29
  • 1
  • 6
1

I had a similar fatal error while building a trivial C++ command line app and using Microsoft Visual Studio Community 2019, version 16.6.2.

Changing the default /LTCG:incremental to /LTCG in project -> properties -> linker -> optimization for release configuration fixed the problem.

Just to add, this error started after one of the recent VS2019 updates (not sure which specific one).

Petr Vepřek
  • 1,547
  • 2
  • 24
  • 35
  • This was the issue for me as well (and the change fixed it). Strange that it seemingly popped up out of nowhere, with builds working fine for years then suddenly receiving the same error as OP. – inspector-g May 01 '23 at 23:08
0

I resolved this issue to link big library in 64-bit. The Visual Studio tries with Default (32-bit linking).

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

Theo
  • 13
  • 5
0

The error C1001 related to compiler file p0io.c is mainly caused by enabling "Use Unicode UTF-8" for worldwide language supporting Region Settings. You could see the link about the concrete reason. You could click

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

and turn off UTF-8.

alseether
  • 1,889
  • 2
  • 24
  • 39
shlomtzi
  • 11
  • 1
  • 2