public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/7538: Constructors of static members are not called always
@ 2002-08-08  3:16 neu
  0 siblings, 0 replies; 7+ messages in thread
From: neu @ 2002-08-08  3:16 UTC (permalink / raw)
  To: gcc-gnats


>Number:         7538
>Category:       c++
>Synopsis:       Constructors of static members are not called always
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 08 03:16:03 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Christian Neubauer
>Release:        gcc version 2.95.3 20010315 (SuSE)
>Organization:
>Environment:
Linux SuSE 8.0
>Description:
This example shows that the instaciation of static class members is not correctly handled depending on the link method. When using g++ to link the list of *.o's everything is correct. When linking with a library it is not. See example. Simply start compile.sh and watch the output.

1. The first version is the correct one. Right before main() the static member m_stClass of classA is constructed, which leads to the output   staticClass:::staticClass() called" before main(). Then main starts and everything is fine.

2. This version shows that the linker does not resolve static member dependencies within libraries. Obviously non-static components like the function int return_five() are handled correctly. The compiler bug is that the staticClass object, which is reqired by classA, is never instanciated.
>How-To-Repeat:
see attached zip-file und execute compile.sh
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-gtar; name="gcc-static-bug.tgz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="gcc-static-bug.tgz"

H4sIAOoMUj0AA+1Y3W/bNhD3M/+Km/uwBKkVSbFswAnWBVkfCuwD6PZe0BRtcZVIjaTsGEH/9x0p
yZbTBC662QFa/R5sfZC8393pjnd8//b2l9/eBvbeDo6GMArDyXg8CBHTSf0fNffuMk7CQThN4vE4
nMRhhOOjeJIMIDwepR0qY6kGGEheHRjHtTkFodPiT1GU+QacESwwVZQi54HJgMoU1tSyDGzGQVW2
rGwA5B0OyjnVbkqm1gYoLBlrJ+rLXMiPXMO8WgaERAH8hZMXQhsLKzSfUBKE8SsypTVnFpTkAbwX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/4jH//JuI//U6Bp8rvdebfT3wtR362/NOEePXr06NGjR48ePXp8Nf4FExHy3AAoAAA=


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: c++/7538: Constructors of static members are not called always
@ 2002-09-25  3:52 nathan
  0 siblings, 0 replies; 7+ messages in thread
From: nathan @ 2002-09-25  3:52 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, neu, nobody

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: c++/7538: Constructors of static members are not called always
@ 2002-09-16  6:26 Christian Neubauer
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Neubauer @ 2002-09-16  6:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7538; it has been noted by GNATS.

From: Christian Neubauer <neu@iis.fhg.de>
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
Cc:  
Subject: Re: c++/7538: Constructors of static members are not called always
Date: Mon, 16 Sep 2002 15:18:04 +0200

 Dear Nathan,
 
 again: the problem is not wether it prints 5 or not. The problem is that 
 it should print
 
 ---------
 staticClass:::staticClass() called
 main() called
 This should result in five: 5
 main() finished
 ----------
 
 however it prints
 
 ----------
 main() called
 This should result in five: 5
 main() finished
 ----------
 
 Obviously the first line "staticClass::...." is missing. This is the bug.
 
 Best regards
 Christian Neubauer
 
 nathan@gcc.gnu.org wrote:
 > Synopsis: Constructors of static members are not called always
 > 
 > State-Changed-From-To: closed->analyzed
 > State-Changed-By: nathan
 > State-Changed-When: Mon Sep 16 06:08:23 2002
 > State-Changed-Why:
 >     confirmed. Please note, that although the testcase appears
 >     to be about 5, it is not.
 >     main() called
 >     This should result in five: 5
 >     main() finished
 >     this is a failure, even though it does produce 5
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7538
 
 
 -- 
 Dr. Christian Neubauer                          Phone: +49 9131 776-355
 FhG-IIS A, Audio & Multimedia                   Mobil: +49  160 5840467
 Am Wolfsmantel 33, D-91058 Erlangen, Germany    Fax:   +49 9131 776-398
 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: c++/7538: Constructors of static members are not called always
@ 2002-09-16  6:08 nathan
  0 siblings, 0 replies; 7+ messages in thread
From: nathan @ 2002-09-16  6:08 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, neu, nobody

Synopsis: Constructors of static members are not called always

State-Changed-From-To: closed->analyzed
State-Changed-By: nathan
State-Changed-When: Mon Sep 16 06:08:23 2002
State-Changed-Why:
    confirmed. Please note, that although the testcase appears
    to be about 5, it is not.
    main() called
    This should result in five: 5
    main() finished
    this is a failure, even though it does produce 5

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7538


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: c++/7538: Constructors of static members are not called always
@ 2002-09-16  4:56 Nathan Sidwell
  0 siblings, 0 replies; 7+ messages in thread
From: Nathan Sidwell @ 2002-09-16  4:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7538; it has been noted by GNATS.

From: Nathan Sidwell <nathan@codesourcery.com>
To: Christian Neubauer <neu@iis.fhg.de>
Cc: nathan@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
   nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: c++/7538: Constructors of static members are not called always
Date: Mon, 16 Sep 2002 12:52:13 +0100

 Christian Neubauer wrote:
 > Dear Nathan,
 > 
 > no the issue is not solved in 3.0.4. I tried (before the submission) and 
 3.0.4 is not maintained. You bug appears fixed in 3.2
 
 nathan
 
 -- 
 Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
           'But that's a lie.' - 'Yes it is. What's your point?'
 nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
 
 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: c++/7538: Constructors of static members are not called always
@ 2002-09-16  1:46 Christian Neubauer
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Neubauer @ 2002-09-16  1:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7538; it has been noted by GNATS.

From: Christian Neubauer <neu@iis.fhg.de>
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
Cc:  
Subject: Re: c++/7538: Constructors of static members are not called always
Date: Mon, 16 Sep 2002 10:38:27 +0200

 Dear Nathan,
 
 no the issue is not solved in 3.0.4. I tried (before the submission) and 
 again today. If you look in the second example the line saying 
 "staticClass::staticClass() called" is not printed. This means that the 
 static member class is not instanciated, what (in my opinion) is a bug.
 
 Please consider the problem again.
 
 Regards
 Christian Neubauer
 
 
 1. link program using gcc and start
 + g++ main.o classA.o staticClass.o -o main
 + ./main
 staticClass:::staticClass() called
 main() called
 This should result in five: 5
 main() finished
 + set +x
 
 2. link program using a library and start
 + ar cru libtest.a classA.o staticClass.o
 + g++ main.o -L. -ltest -o main
 + ./main
 main() called
 This should result in five: 5
 main() finished
 + set +x
 
 
 
 nathan@gcc.gnu.org wrote:
 > Synopsis: Constructors of static members are not called always
 > 
 > State-Changed-From-To: open->closed
 > State-Changed-By: nathan
 > State-Changed-When: Fri Sep 13 16:15:25 2002
 > State-Changed-Why:
 >     works in 3.2
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7538
 
 
 -- 
 Dr. Christian Neubauer                          Phone: +49 9131 776-355
 FhG-IIS A, Audio & Multimedia                   Mobil: +49  160 5840467
 Am Wolfsmantel 33, D-91058 Erlangen, Germany    Fax:   +49 9131 776-398
 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: c++/7538: Constructors of static members are not called always
@ 2002-09-13 16:15 nathan
  0 siblings, 0 replies; 7+ messages in thread
From: nathan @ 2002-09-13 16:15 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, neu, nobody

Synopsis: Constructors of static members are not called always

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Fri Sep 13 16:15:25 2002
State-Changed-Why:
    works in 3.2

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7538


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-09-25 10:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-08  3:16 c++/7538: Constructors of static members are not called always neu
2002-09-13 16:15 nathan
2002-09-16  1:46 Christian Neubauer
2002-09-16  4:56 Nathan Sidwell
2002-09-16  6:08 nathan
2002-09-16  6:26 Christian Neubauer
2002-09-25  3:52 nathan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).