V3 static data in classes vs AIX

Mark Mitchell mark@codesourcery.com
Mon Jun 4 13:58:00 GMT 2001


>>>>> "David" == David Edelsohn <dje@watson.ibm.com> writes:

    David> 	Why is it correct for the header to produce multiple
    David> definitions? 

What do you mean "produce multiple definitions"?  In C++, header files
*must* contain definitions of template static data members so that
you can instantiate them with different types in different places.
That's specifically supported by the language.  

I think you've got a C perspective here, and you think this is like
putting:
 
  int i = 7;

in a header file.  It's not.

I'll go one step further: there is *no way* to produce a broken C++
header that results in multiple definitions of a static data member in
a template unless you put an explicit instantiation in the header
file.  The compilation system *must* allow the definition in the
header, no matter how many times the header is included and how many
times the template is implicitly instantiated.  

In sum, barring extreme insanity, the V3 headers cannot be responsible
for erroneously creating multiple definitions of these template static
data members.

Non-template static data members would be a different situation
altogether.

    David> 	Just because it works, does not mean that it is
    David> correct.  

I'm not sure what you mean.

The goal of the compiler is to transform C++ source into object code
that behaves the way ANSI/ISO C++ says it should.  That is really
the only measure of correctness.  

The compiler uses certain properties of weak symbols on ELF systems to
accomplish the translation.  I have no knowledge that it is incorrect,
in this respect, when presented with an ELF system.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com



More information about the Libstdc++ mailing list