something wrong with template instantiation mechanics

Oleg Krivosheev kriol@fnal.gov
Fri Oct 10 11:46:00 GMT 1997


well, i've reduced example to few lines:

template <class T> class X {
  public:
    X( T );
    X( const X<T>& );
    ~X();
    friend X<T> operator+( const X<T>&, const X<T>& );
  private:
    T t_;
};

template <class T>
X<T>::
X( T t ):
  t_(t) {
}

template <class T>
X<T>::
X( const X<T>& x ):
  t_(x.t_) {
}

template <class T>
X<T>::
~X() {
}

template <class T> X<T>
operator+( const X<T>& a, const X<T>& b ) {
  return X<T>( a.t_ + b.t_ );
}

main( void ) {
}

void
dummy( void ) {
  X<int> x( 1 );
  X<int> y( 2 );

  x = x+y;
}



sparc-solaris2.5.1, gcc version egcs-2.90.12 971008 (gcc2-970802
experimental) 


jor-el ~ $ c++ -c test2.cc
jor-el ~ $ nm -s test2.o |c++filt
00000000 W X<int>::~X(void)
00000030 ? __EXCEPTION_END__
00000000 ? __EXCEPTION_TABLE__
00000000 ? __FRAME_BEGIN__
         U __builtin_delete
00000004 C __eh_cleanup
00000004 C __eh_in_catch
00000004 C __eh_pc
00000004 C __eh_type
00000004 C __eh_value
         U operator+(X<int> const &, X<int> const &)
00000000 W X<int>::X(int)
         U __throw
00000018 T dummy(void)
00000000 t gcc2_compiled.
00000000 T main
         U terminate(void)


as one can see, op+ is not instantiated.

regards

OK




More information about the Gcc mailing list