Bug 9683 - [3.2 regression] bug in initialization chains for static const variables from template classes
Summary: [3.2 regression] bug in initialization chains for static const variables from...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-02-13 02:46 UTC by dohashi
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
bug1.cc (237 bytes, application/octet-stream)
2003-05-21 15:17 UTC, dohashi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dohashi 2003-02-13 02:46:00 UTC
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
Comment 1 dohashi 2003-02-13 02:46:00 UTC
Fix:
Fixed in GCC 3.3, GCC 3.4 with:

http://gcc.gnu.org/ml/gcc-patches/2003-02/msg02219.html
Comment 2 Wolfgang Bangerth 2003-02-14 21:29:45 UTC
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.
Comment 3 Mark Mitchell 2003-02-26 05:39:01 UTC
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
 

Comment 4 Mark Mitchell 2003-02-26 05:39:01 UTC
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
 

Comment 5 Mark Mitchell 2003-02-26 05:55:04 UTC
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
 

Comment 6 Mark Mitchell 2003-02-26 05:55:04 UTC
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
 
Comment 7 Joe Buck 2003-04-25 19:59:58 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for the next release (3.3).