Bug 28620

Summary: [4.1 regression] static const member in template class leads to multiple definitions at linktime
Product: gcc Reporter: Randolph Chung <tausq>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: bangerth, dave, debian-gcc, fang, gcc-bugs, lidaobing, mark, matz, peter.soetens, pinskia, pintaric, rguenth, tausq, tbm
Priority: P3    
Version: 4.1.2   
Target Milestone: ---   
Host: hppa-unknown-linux Target: hppa-unknown-linux
Build: hppa-unknown-linux Known to work: 3.4.6 4.0.4
Known to fail: 4.1.2 Last reconfirmed:
Attachments: testcase

Description Randolph Chung 2006-08-06 10:05:50 UTC
with the attached testcase, during linking you get:
test2.o:(.data+0x0): multiple definition of `_ZN3BadIT_E2_yE'
test1.o:(.data+0x0): first defined here

this comes from a template class:
template <class T>
class Bad {
        static const int _y;
};

template <class T> const int Bad<T>::_y = 1023;

although this seems like a generic c++ problem, it was only observed on hppa-linux and not on other platforms.

this test was simplified from a failure reported in building the quantlib package against g++-4.1. With earlier g++ versions the package builds fine.
Comment 1 Randolph Chung 2006-08-06 10:07:17 UTC
Created attachment 12026 [details]
testcase
Comment 2 Martin Michlmayr 2006-08-06 13:41:29 UTC
This has been fixed already, both in GCC's SVN and in Debian's gcc-4.1 package.

The reason you see it on HPPA is that recent version of gcc-4.1 in Debian don't build.  This bug was fixed in -9 but hppa still has -8.  Can you investigate why recent gcc-4.1 in Debian doesn't compile on HPPA?

gcc-4.1 (4.1.1-9) unstable; urgency=low

  * Update to SVN 20060715.
    - Fix PR c++/28016, do not emit uninstantiated static data members.
      Closes: #373895, #376871.


*** This bug has been marked as a duplicate of 28016 ***