public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jwakely dot gcc at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/32534] gcc fails to initialize template's static data members before their use in some cases
Date: Mon, 15 Jun 2009 09:55:00 -0000	[thread overview]
Message-ID: <20090615095517.3009.qmail@sourceware.org> (raw)
In-Reply-To: <bug-32534-14775@http.gcc.gnu.org/bugzilla/>



------- Comment #4 from jwakely dot gcc at gmail dot com  2009-06-15 09:55 -------
extern "C" int printf(const char*, ...);

struct A
{
        A() : value(1) { printf("A::A %d\n", value); }
        int value;
};

template<class T>
struct B
{
        static A a;
};

template<class T> A B<T>::a = A();

template<class T>
struct C
{
        C()
        {
            printf("C::C %d\n", B<int>::a.value);
            B<int>::a.value = 2;
        }
};

C<float> c;

int main()
{
    printf("main %d\n", B<int>::a.value);
}

compiled with 4.3.2 prints:
C::C 0
A::A 1
main 1

but I expect:
A::A 1
C::C 1
main 2

It seems that the initializer for B<T>::a runs after the initialization of c,
so although the B<int>::a.value gets set by C::C it then gets overwritten by
A::A


-- 


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


  parent reply	other threads:[~2009-06-15  9:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-28 10:36 [Bug c++/32534] New: " vlbel at mail dot ru
2009-06-11 16:34 ` [Bug c++/32534] " rodolfo at rodsoft dot org
2009-06-11 20:03 ` mikpe at it dot uu dot se
2009-06-15  9:20 ` jwakely dot gcc at gmail dot com
2009-06-15  9:55 ` jwakely dot gcc at gmail dot com [this message]
     [not found] <bug-32534-4@http.gcc.gnu.org/bugzilla/>
2011-11-03 18:28 ` richard-gccbugzilla at metafoo dot co.uk
2011-11-03 18:47 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090615095517.3009.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).