> > Hi Guys, > > There appears to be a discrepancy in the way that G++ orders its > static destructors. Given this test program: > > This appears to state that the 3.4.4 compiler got it right. > > The problem I believe is that the destructor for class A is > registered to run using atexit() when the constructor for class B is > run, but the destructor for class B is permanently recorded in the > .dtors section. Since the exit() function runs the things recorded > with atexit() first, before calling _exit() which runs the > destructors in the .dtors section, the destructor for A is called > before the destructor for B. > > Can anyone clarify this for me ? Is this a bug with the current G++ > implementation ?
Your 3.4.x result is correct. But your mainline result is most likely due not using --enable-__cxa_atexit when configuring GCC. This option is required to get the correct behavior of destructors. Now you can ask why --enable-__cxa_atexit is not enabled by default on GNU/Linux machine, I don't have that answer to that question but someone else will. Thanks, Andrew Pinski