[Bug c++/52477] Wrong initialization order? __attribute__((constructor)) vs static data access
jason at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Mar 16 04:46:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52477
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |NEW
Last reconfirmed| |2017-03-16
CC| |jason at gcc dot gnu.org
Resolution|INVALID |---
Ever confirmed|0 |1
--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
I don't think this is undefined; it seems natural for these functions to be
ordered with a translation unit along with dynamic initialization of non-local
variables. So for
---
extern "C" int printf (const char *, ...);
struct A { A() { printf ("A\n"); } } a;
static void B() __attribute__((constructor));
static void B()
{
printf ("B\n");
}
struct C { C() { printf ("C\n"); } } c;
int main() {}
---
I would expect A B C, and gcc currently outputs B A C. Instead of emitting
constructor functions directly into .init_array as we do now, we should
remember them and call them from __static_initialization_and_destruction_0.
Note that 4.6 gave the differently wrong A C B, due to running .init_array in
the opposite order, so this isn't really a regression.
More information about the Gcc-bugs
mailing list