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++ template bug in egcs 1.1.1


The following program illustrates a problem with template functions which occurs with egcs version 1.1.1 but 
not with the FSF gcc version 2.8.1.

Summary: 
  Using egcs 1.1.1, a friend function in a template is not found by the 
  linker when called from within another template function.  If I call
  the friend function explicitly from a non-template function, it is found,
  or if the calling template function is declared as inline.
  
  Note that the error disappears if any optimisation is used (including
  plain -O; it's there if -O0 is used).

System information:
  gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
  GNU ld version 2.9.1 (with BFD 2.9.1)
  Linux sls5tj 2.0.34 #2 Thu Jul 9 10:57:48 EST 1998 i586 unknown
  Pentium Intel 266MHz portable
  
  No arguments to configure when installing egcs.
  
Command line:
  g++ -g bug.cc

Error message:
  /tmp/ccr9PVRv.o: In function `void setnum<Test<int> >(Test<int> &)':
  /home/ccrough/xlib/bug.cc:15: undefined reference to `void doit<int>(int, Test<int> &)'
  collect2: ld returned 1 exit status
  
Source:

template <class T>
struct Test
{
  T num;
  friend void doit(int i, Test& x)
  {
    x.num = i;
  }
};
 
template <class T>
void setnum(T &num)
{
  doit(0, num);
}
 
int
main(int argc, char **argv)
{
  Test<int> t;
 
  setnum(t);
 
  return 0;
}



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