I was struggling with segmentation fault after returning from main in C++0x code compiled under GCC with MinGW, and have narrowed it to simple case:
class A {
public:
virtual ~A();
};
A::~A() {
}
const A a;
int main() {
return 0;
}
The reason is correlated with:
const
qualifier before object, removing it stops seg fault,- Lack of constructor in
class A
- adding empty one stops seg fault. - Version of compialtor - newer TDM MinGW with gcc 4.8.1 does not build code causing seg fault.
Am I triggering some undefined behavior, or really compiler bug is reason of such behavior?
Affected compiler:
gcc --version gcc.exe (tdm-1) 4.7.1
g++ --version g++.exe (tdm-1) 4.7.1
ld --version GNU ld (GNU Binutils) 2.22