This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: g++ static data members [solaris27 + gcc-2.95.2/egcs]


I'm not quite sure this is the same bug, but it looks like 
instanciation of static members of template classes with non default
constructors does not work on linux either. The constructor is not 
called at all. If explicit instantiation is used then the code below
works as intended...

mururoa->cat NoStaticTempInit.C

#include <iostream>

template <class TYPE>
struct A {
    TYPE t;
    A(int x) { t = 1; abort(); }
        static const A cst;
};

template <class TYPE>
const A<TYPE> A<TYPE>::cst(1);

#ifdef EXPLICIT_INSTANCIATION
template class A<double>;
#endif

int
main()
{
    cout << "Static = " << A<double>::cst.t << endl;
    const A<double> I(1);
    cout << "Non static = " << I.t << endl;
}

mururoa->g++ NoStaticTempInit.C
mururoa->./a.out
Static = 0
Abort

mururoa->g++ -v
Reading specs from /net/home/robotvis/gnu/egcs/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
gcc version 2.96 20000214 (experimental)

--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
 --------------------------------------------------------------------



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]