bug: static data member template

Bryan D. Green bgreen@nas.nasa.gov
Thu Jun 17 19:18:00 GMT 1999


I've found a bug in the use of static data member templates.

I'm attaching the 'statictest.ii' file resulting from 'g++ -save-temps 
statictest.C'.

Here's the code:

--- BEGIN CODE ------

template<class T>
class Val {
public:
    static const T tval;
};

template <class T>
const T Val<T>::tval = 0.0;

const float *fp(&Val<float>::tval);

template class Val<float>;

--- END CODE ---

Here's the output:

> g++ -save-temps statictest.C
/usr/lib/crt1.o(.text+0x36): undefined reference to `main'
statictest.o(.data+0x0): undefined reference to `Val<float>::tval'
collect2: ld returned 1 exit status

Commentary:

Note that the static data member does not get instantiated in this case.
If you move line 11 below line 13, it will instantiate properly.
If you remove all the 'const' specifiers, it will instantiate properly.

System Info:

> uname -a
Linux yyz 2.2.4 #4 Thu Mar 25 09:33:32 PST 1999 i686 unknown
> g++ -v
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

-bryan




More information about the Gcc-bugs mailing list