__attribute__((constructor)) doesn't work in C++ for both gcc-3.4.1 and gcc-3.5.0 20040725 when optimization level -O2 is being used. All seems to work Ok with gcc-3.3.4. -------------------- bug.cc ---------------------- #include <stdio.h> void hello (void) __attribute__ ((constructor)); void hello (void) { printf ("Hello world\n"); } int main (void) { return 0; } --------------------------------------------------- g++ -O2 bug.cc -o bug ./bug works with gcc-3.3.4, but not with gcc-3.4.1 and 3.5.0 20040725 (Initially bug were reported for target i586-pc-msdosdjgpp)
This works in GCC 3.5 now.
Subject: Bug 16717 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: mmitchel@gcc.gnu.org 2004-08-12 02:49:39 Modified files: gcc/cp : ChangeLog semantics.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/ext: construct1.C Log message: PR c++/16717 * semantics.c (expand_body): Do not update static_ctors and static_dtors here. (expand_or_defer_fn): Do it here, instead. PR c++/16717 * g++.dg/ext/construct1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.142&r2=1.3892.2.143 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.381.4.12&r2=1.381.4.13 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.245&r2=1.3389.2.246 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/construct1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
Subject: Bug 16717 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-08-12 02:51:31 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/ext: construct1.C Log message: PR c++/16717 * g++.dg/ext/construct1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4120&r2=1.4121 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/construct1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
Fixed in GCC 3.4.2.