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

Reply via email to