I have code that fails to compile with Visual Studio 2015 Community Edition with the following error:
fatal error C1002: compiler is out of heap space 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; };
B A::b;
int main() {
return 0;
}
This is the simplest I've been able to boil down the fail state through trial and error, but there's still quite a bit going on.
What has me dumbfounded is that each of the following changes cause it to compile just fine...
Removing constexpr from B's constructor 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; };
B A::b;
int main() {
return 0;
}
Changing A's variable to be not 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; }; B A::b; )
int main() {
return 0;
}
Using a plain int in B's union's 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; };
B A::b;
int main() {
return 0;
}
Default-initializing x in B's constructor rather than 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; };
B A::b;
int main() {
return 0;
}
Finally, taking B's union's Int member out of structs makes it work:
struct Int { int i; };
struct B {
union {
struct { int x; };
Int y; // <---<< ( struct { Int y; }; )
};
constexpr B() : x(1) {}
};
struct A { static B b; };
B A::b;
int main() {
return 0;
}
Suffice to say, I'm at a complete loss. I would greatly appreciate any assistance from someone who understands the compiler better than I do.