The compiler leaves the heap area in pass 2 - anonymous union, anonymous structures, constexpr constructor, static member

I have code that does not compile with Visual Studio 2015 Community Edition with the following error:

fatal error C1002: compiler exits heap area in pass 2

The code

struct Int { int i; }; struct B { union { struct { int x; }; struct { Int y; }; }; constexpr B() : x(1) {} }; struct A { static B b; }; BA::b; int main() { return 0; } 

It is the simplest that I was able to collapse the failure state through the trial version and the error, but it still continues a bit.

What struck me was that each of the following changes made it compile just a fine ...

Removing the constexpr constructor from B makes it work:

 struct Int { int i; }; struct B { union { struct { int x; }; struct { Int y; }; }; B() : x(1) {} // <---<< ( constexpr B() : x(1) {} ) }; struct A { static B b; }; BA::b; int main() { return 0; } 

Changing the variable A will not be static makes it work:

 struct Int { int i; }; struct B { union { struct { int x; }; struct { Int y; }; }; constexpr B() : x(1) {} }; struct A { B b; }; // <---<< ( struct A { static B b; }; BA::b; ) int main() { return 0; } 

Using a simple int in a B union second struct instead of an int wrapper makes it work:

 struct Int { int i; }; struct B { union { struct { int x; }; struct { int y; }; // <---<< ( struct { Int y; }; ) }; constexpr B() : x(1) {} }; struct A { static B b; }; BA::b; int main() { return 0; } 

By default, initializing x in the B constructor instead of passing 1 makes it work:

 struct Int { int i; }; struct B { union { struct { int x; }; struct { Int y; }; }; constexpr B() : x() {} // <---<< ( constexpr B() : x(1) {} ) }; struct A { static B b; }; BA::b; int main() { return 0; } 

Finally, taking the B union int member from the structures, it works:

 struct Int { int i; }; struct B { union { struct { int x; }; Int y; // <---<< ( struct { Int y; }; ) }; constexpr B() : x(1) {} }; struct A { static B b; }; BA::b; int main() { return 0; } 

Suffice it to say that I have a complete loss. I would really appreciate any help from those who are better versed in the compiler than me.

+6
source share

All Articles