This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ static data members [solaris27 + gcc-2.95.2/egcs]
- To: Benjamin Kosnik <bkoz at cygnus dot com>
- Subject: Re: g++ static data members [solaris27 + gcc-2.95.2/egcs]
- From: Theodore Papadopoulo <Theodore dot Papadopoulo at sophia dot inria dot fr>
- Date: Mon, 06 Mar 2000 19:43:48 +0100
- cc: gcc-bugs at gcc dot gnu dot org
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
--------------------------------------------------------------------