This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: G++: Order of static destructors ?
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: nickc at redhat dot com (Nick Clifton)
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 13 Feb 2006 08:05:16 -0500 (EST)
- Subject: Re: G++: Order of static destructors ?
>
> 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