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 initialised


On Mon, Mar 17, 2003 at 12:04:17PM -0000, nathan at gcc dot gnu dot org wrote:
> Date: 17 Mar 2003 12:04:17 -0000
> To: O dot Kullmann at Swansea dot ac dot uk, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org,
>    nobody at gcc dot gnu dot org
> From: nathan at gcc dot gnu dot org
> Reply-To: nathan at gcc dot gnu dot org, O dot Kullmann at Swansea dot ac dot uk, gcc-bugs at gcc dot gnu dot org,
>    gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
> X-Mailer: gnatsweb 2.9.3
> Subject: Re: c++/10112: static data member is not correctly initialised
> X-Spam-Status: No, hits=-99.3 required=8.0
> 	tests=NO_REAL_NAME,USER_IN_WHITELIST
> 	version=2.50
> X-Spam-Level: 
> X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp)
> 
> Synopsis: static data member is not correctly initialised
> 
> State-Changed-From-To: open->analyzed
> State-Changed-By: nathan
> State-Changed-When: Mon Mar 17 12:04:17 2003
> State-Changed-Why:
>     the ordering of these two template instantiations is implementation defined. I think there's an algorithm to get
>     the order right
>     
>     nathan
> 
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10112

Hi,

(I hope that's the right way to reply?!)

hmhm, might be. I guess the relevant sentence is

in particular, the initialization (and any associated side-effects) of a static data member does not occur unless the static data member is itself used in a way that requires the definition of the static data member to exist.

(section 14.7.1 of ISO/IEC 14882:1998(E)),

and thus one could conclude that in Giovanni's example in the instruction

assert(B<int>::p1 == B<int>::a.p);

the order of initialisations depends on the order of evaluation of the equality
expression, which is implementation defined.

Is this the interpretation?!

The best solution (which might also be a better design) seems to me, to put the
static data member (in the example, of class B) into a new (local) class X (or struct),
for which we provide a constructor guaranteeing the right order of initialisation. 
The host class B then has one static data member of type X. When we first use this
data member, it will be constructed using the right order of initialisation.

Sounds okay to me. (Worked in my case.)

Thanks for your help!

Oliver

-- 
Dr. Oliver Kullmann
Computer Science Department
University of Wales Swansea
Faraday Building, Singleton Park
Swansea SA2 8PP, UK
http://cs-svr1.swan.ac.uk/~csoliver/


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