public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32534]  New: gcc fails to initialize template's static data members before their use in some cases
@ 2007-06-28 10:36 vlbel at mail dot ru
  2009-06-11 16:34 ` [Bug c++/32534] " rodolfo at rodsoft dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: vlbel at mail dot ru @ 2007-06-28 10:36 UTC (permalink / raw)
  To: gcc-bugs

the following programm
-----------------------------------------------
#include <iostream>

struct A
{
        A() : value(0) {}
        int value;
};

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

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

template<class T>
struct C
{
        C() { B<int>::a.value = 1; }
};

C<float> c;

main()
{
        std::cout << B<int>::a.value << std::endl;
}

-------------------------------------------------
prints 0 instead of expected 1.
It is important that C is template. Otherwise (if C is ordinary class) the
output is 1.
If I use "template<> A B<int>::a;" instead of "template<class T> A B<T>::a;" I
got linker error: undefined reference to 'B<int>::a'.
I can't use "template<> A B<int>::a = something;" form (which would help)
because I have only empty ctor (like in the case of map).


-- 
           Summary: gcc fails to initialize template's static data members
                    before their use in some cases
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vlbel at mail dot ru


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


^ permalink raw reply	[flat|nested] 7+ messages in thread
[parent not found: <bug-32534-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-11-03 18:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-28 10:36 [Bug c++/32534] New: gcc fails to initialize template's static data members before their use in some cases 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
     [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

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