Bug 28327 - const static members generate .data defs
Summary: const static members generate .data defs
Status: RESOLVED DUPLICATE of bug 28016
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-10 08:12 UTC by Michael Matz
Modified: 2006-07-10 08:53 UTC (History)
10 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***