Bug 4151 - egcs can't link when using a template function
Summary: egcs can't link when using a template function
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: egcs
Version: 6.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 1999-07-22 00:06 UTC by Brian Gunney
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 1999-09-01 03:36:15 UTC

Attachments (Terms of Use)

Description Brian Gunney 1999-07-22 00:06:26 UTC
Program provoking bug:

template < class lstype >
class X { friend void mod(X *r) {} };
template < class T >
void slam ( T *value )  { char *p; mod ( value ); }
int main( int argc, char **argv ) {
  X<double> x;
  slam( &x );
#if 0 // Changing this 0 to 1 has an effect on success of
  mod( &x );

Compilation output:

g++ ec.cc
/tmp/ccoqLzDf.o: In function `void slam<X<double>
>(X<double> *)':
/tmp/ccoqLzDf.o(.void gnu.linkonce.t.slam<X<double>
>(X<double> *)+0xb): undefined reference to `void
mod<double>(X<double> *)'
collect2: ld returned 1 exit status

Calling mod from main seems to cause the function to be
instantiated, but as is, mod is NOT being instantiated.

using egcs-1.1.2-12, egcs-c++-1.1.2-12, kernel-2.2.5-15


Comment 1 igmar 1999-07-22 10:44:59 UTC
Hmm. I had the same problem when using stringfunctions in normal C.
Turned out there where infact macro's. Solved it by putting the
function name beween ()'s.

Comment 2 Jim Kingdon 1999-07-26 21:15:59 UTC
Putting mod in parentheses has no effect, so the comment about
macros seems to be inapplicable to this test case.

Comment 3 Jim Kingdon 1999-09-01 03:36:59 UTC
I was able to reproduce this with the GCC (version egcs 1.1.2) which
ships with Red Hat 6.0.  If I use the latest GCC from
http://gcc.gnu.org/, the problem goes away.  Therefore, I conclude
that this is one of the many C++ fixes in the latest GCC.  So the
good news is that the fix exists.  The bad news is that upgrading to
that compiler involves recompiling all C++ libraries (e.g. stdc++)
due to changes in the C++ ABI.  Because of this compatibility
issue, Red Hat Linux will not be shipping with this newer compiler
for some time to come.

Note You need to log in before you can comment on or make changes to this bug.