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]

[C++]: Definition of static member of templates with initialization!



OS: OSF1 slbhdg V4.0 1229 alpha
GCC: 2.95.2


Hi,

yesterday I have installed the GCC on our alpha machine. All went
well. My first test compilation of some C++ code of mine, was
successful. But then I have tried to compile a code, that heavily rely
on templates.

The compilation was successful, but the linker moaned, that it cannot
resolve the symbol to a static member of the template class. The same
compilation with the same compiler version was ok for:

- SunOS slbh88 5.7 Generic_106541-07 sun4u sparc SUNW,Ultra-Enterprise
- Linux 2.2.10

After some investigation of the assembler output, it seems to me, that
the definition of the static member will not find its way into the .s
file, *IF* I do both *define* the static member, and *initialize* it
with the same statement.

That means:

   template <class T>
   int Test<T>::val;

will work, but if I do this:

   template <class T>
   int Test<T>::val = 0;

the C++ compiler will not forsee storage for this member! So the
linker will complain!!!

I have attached a bzipped tarfile containing following files:

   tst.cc       - Source that show you the wrong behavior
   tst.log      - [c++ -v --save-temps -o tst tst.cc >& tst.log]
   tst.ii       - You know :-)
   tst.s        - That too ;-)

If there is a patch to solve that problem, could you tell me, how I
can find it?

Thanks in advance for all,

Clemens Hintze

bug_tst.tar.bz2


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