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]

Bug in explicit template instantiation in presence of a static member (which is defined in terms of a nested templated class)


Under egcs-2.91.13 and egcs-2.91.15, the following code:

template <class A>
class TEST
{
public:
  TEST (A);
};

template <class A>
class TEST2
{
  static A i;
};

template <class A>
A TEST2 <A>::i (0);

TEST2 <TEST <int> > a;
TEST2 <TEST <int> > b;

template class TEST2 <TEST <int> >;

produces:

S rittle@supra; g++ -v -c t.cpp
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.13/specs
gcc version egcs-2.91.13 980308 (gcc-2.8.0 release)
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.13/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) t.cpp /var/tmp/ccLJuxP_.ii
GNU CPP version egcs-2.91.13 980308 (gcc-2.8.0 release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/share/gcc/egcs-2.91.13/include/g++
 /usr/local/lib/g++-include
 /usr/local/include
 /usr/local/sparc-sun-solaris2.6/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.13/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.13/cc1plus /var/tmp/ccLJuxP_.ii -quiet -dumpbase t.cc -version -o /var/tmp/ccLJuxP_.s
GNU C++ version egcs-2.91.13 980308 (gcc-2.8.0 release) (sparc-sun-solaris2.6) compiled by GNU C version egcs-2.91.13 980308 (gcc-2.8.0 release).
t.cpp:15: multiple initializations given for `TEST2<TEST<int> >::i'

If the template is not explicitly instantiated (i.e. remove the last
line of the example), then neither compile-time nor link-time errors
are produced in the code above or the code from which this example was
abstracted.

Aside: This example was abstracted out of 100,000 lines of
preprocessed ACE code (http://www.cs.wustl.edu/~schmidt/ACE.html).
Even more so than STL, that software exercises a C++ compiler's
ability to handle complex templates properly.

Another aside: Other error messages produced by egcs inform the
programmer where the conflicting (or redundant or duplicate)
definitions occur.  This is a very nice feature.  The error message
given in this case (while granted should not have been generated at
all) lacks a pointer to the source code which contains the duplicate
definition.

Thanks to all the people putting huge amounts of effort into egcs's
C++ support.

Regards,
Loren
-- 
Loren J. Rittle (rittle@comm.mot.com)	PGP KeyIDs: 1024/B98B3249 2048/ADCE34A5
Systems Technology Research (IL02/2240)	FP1024:6810D8AB3029874DD7065BC52067EAFD
Motorola, Inc.				FP2048:FDC0292446937F2A240BC07D42763672
(847) 576-7794				Call for verification of fingerprints.


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