Initialization chains of static const variables in templates does not work properly. If a variable is initialized by a chain of two variables, neither of which is referenced, then the intialization does not occur. template <class data> const int foo<data>::a = 1; template <class data> const int foo<data>::b = a; template <class data> const int foo<data>::c = b; template <class data> const int foo<data>::d = c; c and d will not be initialized properly if a and b are not used. If a is used, c will be initiailized, but d will not be. Release: 3.2.1 Environment: slackware-current Configured with: ../gcc-3.2.1/configure --prefix=/usr --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --target=i386-slackware-linux --host=i386-slackware-linux Thread model: posix gcc version 3.2.1 How-To-Repeat: hades:~/project/gcc-bug> g++ bug1.cc hades:~/project/gcc-bug> ./a.out 0 0 hades:~/project/gcc-bug> g++ -DA_C bug1.cc hades:~/project/gcc-bug> ./a.out 1 1 hades:~/project/gcc-bug> g++ -DA_D bug1.cc hades:~/project/gcc-bug> ./a.out 1 0
Fix: Fixed in GCC 3.3, GCC 3.4 with: http://gcc.gnu.org/ml/gcc-patches/2003-02/msg02219.html
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. A regression in 3.2/3.3/3.4 against 2.95. It also fails in 3.0.4, by the way. May or may not be related to 9674. W.
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/9683 Date: 26 Feb 2003 05:39:01 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-02-26 05:39:01 Modified files: gcc/cp : ChangeLog decl2.c pt.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: static3.C Log message: PR c++/9683 * decl2.c (prune_vars_needing_no_initialization): Do not throw away initializations for DECL_EXTERNAL VAR_DECLs. (finish_file): Adjust accordingly. * pt.c (instantiate_decl): Do not defer VAR_DECLs. PR c++/9683 * g++.dg/template/static3.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3216&r2=1.3217 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.599&r2=1.600 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.665&r2=1.666 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2447&r2=1.2448 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
From: mmitchel@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/9683 Date: 26 Feb 2003 05:55:04 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-02-26 05:55:04 Modified files: gcc/cp : decl2.c pt.c Added files: gcc/testsuite/g++.dg/template: static3.C Log message: PR c++/9683 * decl2.c (prune_vars_needing_no_initialization): Do not throw away initializations for DECL_EXTERNAL VAR_DECLs. (finish_file): Adjust accordingly. * pt.c (instantiate_decl): Do not defer VAR_DECLs. PR c++/9683 * g++.dg/template/static3.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.575.2.9&r2=1.575.2.10 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.8&r2=1.635.2.9 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed for the next release (3.3).