From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 693 invoked by alias); 25 Sep 2002 10:52:11 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 674 invoked by uid 61); 25 Sep 2002 10:52:10 -0000 Date: Wed, 25 Sep 2002 03:52:00 -0000 Message-ID: <20020925105210.673.qmail@sources.redhat.com> To: gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, neu@iis.fhg.de, nobody@gcc.gnu.org From: nathan@gcc.gnu.org Reply-To: nathan@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, neu@iis.fhg.de, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: c++/7538: Constructors of static members are not called always X-SW-Source: 2002-09/txt/msg00662.txt.bz2 List-Id: Synopsis: Constructors of static members are not called always State-Changed-From-To: analyzed->closed State-Changed-By: nathan State-Changed-When: Wed Sep 25 03:52:09 2002 State-Changed-Why: not a bug. [3.6.2]/3 says dynamic initialization may be delayed, but must be done before the first use of any function or object defined in the same TU as the object to be initialized. The TU which defines ClassA::m_stClass is classA.cpp. The main program uses ClassA::ClassA, ClassA::~ClassA and ClassA::returns_five. All those are inline functions defined in classA.hpp. [3.2]/3 says an inline function shall be defined in every TU in which it is used. As those inline functions are defined in main.cpp. Hence we never use anything defined in the TU classA.cpp, and so never need to initialize classA::m_stClass. The reason you see different behaviours with a library vs explicit classA.o, is that in the latter case the linker is forced to include classA.o in the final executable, that pulls in the static ctor function for that object file. With a library, classA.o is only pulled in, if something explicitly references an object/function defined within it. Should that happen then all of classA.o is pulled in, which will include the static ctor function. The standard permits this. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7538