static data member template not initialized
Mathias Doreille
Mathias.Doreille@imag.fr
Wed Feb 3 02:46:00 GMT 1999
* version of GNU CC
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
* config.status
#!/bin/sh
# This file was generated automatically by configure. Do not edit.
# This directory was configured as follows:
./configure --with-gcc-version-trigger=/usr/local/server/lude/egcs-1.1.1/src/imag/sparc_sun_solaris2.6/gcc/version.c --host=sparc-sun-solaris2.6 --prefix=/usr/local/soft/egcs-1.1.1/run/imag/sparc_sun_solaris2.6 --norecursion
# using "mh-frag"
* type of machine
sparc-sun-solaris2.6
* input file
//**********************************************************************
#include <iostream.h>
class A {
public:
A() {
cout << "build of object of type A at address " << this << endl;
value = 98765;
}
int value;
};
class B {
public:
virtual void print() = 0;
};
template<class T>
class C : public B {
public:
static A t;
void print() {
cout << "value of static object C< ? >::t at address " <<
&t << " equal " << t.value;
if( t.value == 98765 )
cout << " => correct, static object is initialised" << endl;
else
cout << " => error, static object is not initialized" << endl;
}
};
template<class T>
A C<T>::t;
main()
{
cout << "begin of main function" << endl;
B* h = new C<int>;
h->print();
}
//**********************************************************************
* gcc command arguments
gcc file.C
* bug
Incorrect output when the program is run.
One observe that the static data member template C<int>::t
required by the virtual function member template C<int>::print() and
implicitly instantiated by the compiler is not initialized (its
constructor is not call).
--
| Mathias DOREILLE | LMC-IMAG, Institut Fourie |
| e.mail: Mathias.Doreille@imag.fr | 100, rue des Mathematiques |
| Tel: (+33) 4 76 51 45 74 | Domaine Universitaire |
| Fax: (+33) 4 76 51 48 46 | BP 53, F-38041 GRENOBLE cedex 9 |
More information about the Gcc-bugs
mailing list