egcs-1.0.2: static members of template classes

Munagala V. S. Ramanath
Mon Apr 20 10:15:00 GMT 1998

The following program compiled with egcs-1.0.2 generates the following
linker error:

ld: Undefined symbol 

If the explicit class instantiation is uncommented, everything works.

Version info:
Reading specs from /d2a/exper/lib/gcc-lib/sparc-sun-sunos4.1.2/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)

----------  CUT HERE  ---------------------------  CUT HERE  -----------
// egcs-1.0.2 complains about undefined symbols; if the explicit
// instantiation is uncommented, everything works ok.
#include <fstream.h>

template< class T >
struct A {
    A( long size ) {i = size;}

    static long i;

// definition of static member as in Stroustrup, section C.13.1, p. 854
template< class T > long A< T >::i = 0;

A< long > a( 10 );

// for some reason, egcs-1.0.2 needs this explicit instantiation
//template A< long >;

    return 0;

More information about the Gcc-bugs mailing list