public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17910] New: wrong order of static initialization
@ 2004-10-09 13:27 kunert at physik dot tu-dresden dot de
  2004-10-09 14:36 ` [Bug c++/17910] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: kunert at physik dot tu-dresden dot de @ 2004-10-09 13:27 UTC (permalink / raw)
  To: gcc-bugs

#include <iostream>
using namespace std;

struct A {
    int x;
    A(){ x = 17; }
};

template<class T>
struct B {
    static A a;
    int x;
    B(){ x = a.x; }
};

template<class T>
A B<T>::a;

B<int> b;

int main()
{
    cout << b.x  << ' ' << b.a.x << endl;
}

The abould code should initialize B<int>::a before the global static b,
resulting in '17 17'. However, the actual output is '0 17'.

-- 
           Summary: wrong order of static initialization
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kunert at physik dot tu-dresden dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17910


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

* [Bug c++/17910] wrong order of static initialization
  2004-10-09 13:27 [Bug c++/17910] New: wrong order of static initialization kunert at physik dot tu-dresden dot de
@ 2004-10-09 14:36 ` pinskia at gcc dot gnu dot org
  2004-10-09 15:57 ` kunert at physik dot tu-dresden dot de
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-09 14:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-09 14:36 -------


*** This bug has been marked as a duplicate of 10112 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17910


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

* [Bug c++/17910] wrong order of static initialization
  2004-10-09 13:27 [Bug c++/17910] New: wrong order of static initialization kunert at physik dot tu-dresden dot de
  2004-10-09 14:36 ` [Bug c++/17910] " pinskia at gcc dot gnu dot org
@ 2004-10-09 15:57 ` kunert at physik dot tu-dresden dot de
  2004-10-09 18:07 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: kunert at physik dot tu-dresden dot de @ 2004-10-09 15:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kunert at physik dot tu-dresden dot de  2004-10-09 15:57 -------
Subject: Re:  wrong order of static initialization

10112 is a mess.
The original testcase there does not fail anymore. This makes it
very difficult for bug submitters to recognize it as a duplicate,
resulting in lots of wasted bug reports.

pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-09 14:36 -------
> 
> 
> *** This bug has been marked as a duplicate of 10112 ***
> 



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17910


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

* [Bug c++/17910] wrong order of static initialization
  2004-10-09 13:27 [Bug c++/17910] New: wrong order of static initialization kunert at physik dot tu-dresden dot de
  2004-10-09 14:36 ` [Bug c++/17910] " pinskia at gcc dot gnu dot org
  2004-10-09 15:57 ` kunert at physik dot tu-dresden dot de
@ 2004-10-09 18:07 ` bangerth at dealii dot org
  2004-10-09 18:41 ` pinskia at gcc dot gnu dot org
  2004-10-14 14:33 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2004-10-09 18:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-10-09 18:07 -------
Then let's keep this one open. Whoever fixes it should double-check 
the other one as well. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17910


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

* [Bug c++/17910] wrong order of static initialization
  2004-10-09 13:27 [Bug c++/17910] New: wrong order of static initialization kunert at physik dot tu-dresden dot de
                   ` (2 preceding siblings ...)
  2004-10-09 18:07 ` bangerth at dealii dot org
@ 2004-10-09 18:41 ` pinskia at gcc dot gnu dot org
  2004-10-14 14:33 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-09 18:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-09 18:41 -------
Well this is undefined which is why this is a dup of bug 10112 and nothing more.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17910


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

* [Bug c++/17910] wrong order of static initialization
  2004-10-09 13:27 [Bug c++/17910] New: wrong order of static initialization kunert at physik dot tu-dresden dot de
                   ` (3 preceding siblings ...)
  2004-10-09 18:41 ` pinskia at gcc dot gnu dot org
@ 2004-10-14 14:33 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-14 14:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-14 14:33 -------
Even though the testcase in PR 10112 is fixed (or is it), the problem is the same, the order in this case 
is undefined.

*** This bug has been marked as a duplicate of 10112 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17910


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

* [Bug c++/17910] wrong order of static initialization
       [not found] <bug-17910-2109@http.gcc.gnu.org/bugzilla/>
@ 2009-11-08 23:24 ` jason at gcc dot gnu dot org
  0 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-08 23:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jason at gcc dot gnu dot org  2009-11-08 23:24 -------
14.7.4.1 [temp.point] says:

...the point of instantiation for such a specialization immediately follows the
namespace scope declaration or definition that refers to the specialization.

So, the point of instantiation for B<int>::B(), and thus for B<int>::a, is
*after* the declaration of b, and therefore there's no reason to expect
B<int>::a to be initialized before b.

If you need B<int>::a to be initialized before b, you can provide an explicit
instantiation:

template A B<int>::a;
B<int> b;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17910


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

end of thread, other threads:[~2009-11-08 23:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-09 13:27 [Bug c++/17910] New: wrong order of static initialization kunert at physik dot tu-dresden dot de
2004-10-09 14:36 ` [Bug c++/17910] " pinskia at gcc dot gnu dot org
2004-10-09 15:57 ` kunert at physik dot tu-dresden dot de
2004-10-09 18:07 ` bangerth at dealii dot org
2004-10-09 18:41 ` pinskia at gcc dot gnu dot org
2004-10-14 14:33 ` pinskia at gcc dot gnu dot org
     [not found] <bug-17910-2109@http.gcc.gnu.org/bugzilla/>
2009-11-08 23:24 ` jason at gcc dot gnu dot org

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).