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] inconsistancy with specialization and namespace...



Hi,

Recently I send a bug report which was actually a problem in my
program. But this highligthed a Bug on the compiler. The problem is
about the use of a template before an explicit specialization.

Specifically, the following code doesn't abort nor gives any error
report on egcs1.1.1


template <class T, const int D> 
struct Point {
  T data[D];
};

template <class T> class Vector;

template <class T> void resizeG(Vector<T>&, int );

template <class T>
class Vector {
public:
  resize(int n) { resizeG(*this,n); }
  
  friend void resizeG<>(Vector<T>&,int);
  friend void resizeG<>(Vector<Point<float,3> >&,int);
};

template <class T> void resizeG(Vector<T>&, int ) { abort() ;}

template<>
void resizeG<Point<float,3> >(Vector<Point<float,3> >& , int ) { ;}

int main(){
  Vector<Point<float,3> > vec ;
  vec.resize(10);
}

resizeG<Point<float,3> > is specialized after it's being refered to in
the member function resize. In a single code like the above the same
behavior is seen with both a namespace or without (as above).

However, if I split the files, I'm getting a different results
depending if a namespace is used or not. With a namespace, I get a
linker error.

nameMain.o: In function `Test::Vector<Point<float, 3> >::resize(int)':
nameMain.o(.Test::Vector<Point<float, 3> >::gnu.linkonce.t.resize(int)+0x14): undefined reference to `void Test resizeG<Point<float, 3> >(Test::Vector<Point<float, 3> > &, int)'
collect2: ld returned 1 exit status

Without the namespace evertyhing works fine and the program runs
without aborting.

The test files follow

I hope this helps

Phil

friend.tar



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