This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/10112: static data member is not correctly initialized


"Giovanni Bajo" <giovannibajo at libero dot it> writes:

| ----- Original Message -----
| From: "Gabriel Dos Reis" <gdr at integrable-solutions dot net>
| To: "Giovanni Bajo" <giovannibajo at libero dot it>
| Cc: "Wolfgang Bangerth" <bangerth at ticam dot utexas dot edu>;
| <gcc-gnats at gcc dot gnu dot org>; <gcc-bugs at gcc dot gnu dot org>; <o dot kullmann at swansea dot ac dot uk>;
| <nathan at gcc dot gnu dot org>
| Sent: Tuesday, March 18, 2003 2:46 AM
| Subject: Re: c++/10112: static data member is not correctly initialized
| 
| 
| >From which parts of the standard did read that?
| 
| I was reading §3.6.2p1 <<before any other initialization takes place>> in
| this way.

That paragraph speaks about initialisation of objects.  It says
nothing about the order of template instantiations and the order


| Anyway, the bug is about the order of initialization between two static data
| members. Since instantiation of class templates does not affect
| initialization of static data members (as per quoted paragraph), even if you
| instantiate the class templates before inizializing the data members, you
| should respect the order of inizialization of the data members.

Unless the instantiation of the class template uses the static data
members. 

| It seems to me that GCC is initializing the static data members because the
| templates are instantiated, but this violates §14.7.1p8.

What you're missing is  that your expression in the assertion
introduces an indeterminism in the order of instantiation.  It is the
instantiation of the static data members that defines them, not just
their mere -template- definition.

What is happening is not far from the following scenario: 

   struct A { 
      int p;
 
      A(int x) : p(x) { }
   }; 

   struct B {
      static A a;
      static int p1;
   };

    int B::p1 = a.p;
    A B::a(123);

  int main()
  {
    assert (B::a.p == B::p1);
  } 

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]