User account creation filtered due to spam.

Bug 28327

Summary: const static members generate .data defs
Product: gcc Reporter: Michael Matz <matz>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: bangerth, debian-gcc, fang, gcc-bugs, lidaobing, mark, matz, pinskia, pintaric, tbm
Priority: P3    
Version: 4.1.2   
Target Milestone: ---   
Host: i386-linux Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Michael Matz 2006-07-10 08:12:36 UTC
Compile this with current 4.1 branch (verified with 4.1.2 20060710):

% cat one.ii
template <typename T>
struct One {
  static const int A;
};
template <typename T>
const int One<T>::A = 5;
int f()
{
  return One<int>::A;
}
% ./gcc/cc1plus one.ii && gcc -c one.s && nm one.o | c++filt
         U __gxx_personality_v0
00000000 T f()
00000000 D _ZN3OneIT_E1AE

(strangely enough the name _ZN3OneIT_E1AE can't be demangled, but that's
secondary).

The important point is that this is a template member, which is not defined 
as weak or linkonce symbol.  This breaks when the template is instantiated
in multiple .o files (it occurred while compiling obby).

Interestingly it depends on the member being marked "const".  Without it
the symbols look right:
00000000 V One<int>::A

With 4.1.0 this generated no .data objects at all (presumably by optimizing
away all references to it, by using the constness), and hence no symbol
conflicts, so something changed till 4.1.0.
Comment 1 Andrew Pinski 2006-07-10 08:53:21 UTC

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