Article View: gnu.g++.bug
Article #11742.3.3: template/operator- bug
From: Doug Moore
Date: Mon, 28 Dec 1992 08:01
Date: Mon, 28 Dec 1992 08:01
57 lines
2422 bytes
2422 bytes
In the following program, I find that a friend binary operator - and a
member operator - w/ no args cannot co-exist in the same template class;
the result of an attempt is a link error.
Note that if the member minus without args is replaced by a friend
minus with one arg, the problem disappears.
First the compiler: gcc 2.3.3, original sources, on a sparc (sunos
4.1.2).
The compiler output:
==============================================================================
g++ -v -Wall bug.cc
Reading specs from /blossom/lib/gcc-lib/sun4/2.3.3/specs
gcc version 2.3.3
/blossom/lib/gcc-lib/sun4/2.3.3/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -Wall bug.cc /usr/tmp/cca05901.i
GNU CPP version 2.3.3 (sparc)
/blossom/lib/gcc-lib/sun4/2.3.3/cc1plus /usr/tmp/cca05901.i -quiet -dumpbase bug.cc -Wall -version -o /usr/tmp/cca05901.s
GNU C++ version 2.3.3 (sparc) compiled by GNU C version 2.3.3.
as -o /usr/tmp/cca059011.o /usr/tmp/cca05901.s
/blossom/lib/gcc-lib/sun4/2.3.3/ld -e start -dc -dp /lib/crt0.o -L/blossom/lib/gcc-lib/sun4/2.3.3 -L/blossom/lib /usr/tmp/cca059011.o -lg++ -lgcc -lc -lgcc
ld: Undefined symbol
___mi__FRCt6Number1ZiT0
collect: /usr/bin/ld returned 2 exit status
==============================================================================
The source:
==============================================================================
template<class T>
class Number
{
public:
friend Number operator- (const Number& src1, const Number& src2);
Number operator- () const;
T data;
};
template <class T>
inline Number<T>
operator- (const Number<T>& src1, const Number<T>& src2)
{
Number<T> dst;
dst.data = src1.data - src2.data;
return dst;
}
main()
{
Number<int> a, b, c;
b.data = 1;
c.data = 2;
a = b - c;
}
==============================================================================
Doug Moore
(dougm@cs.rice.edu)
Technical Details
Message-ID:
<9212280801.AA05912@cs.rice.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.rice.edu!dougmShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.rice.edu!dougm From: dougm@cs.rice.edu (Doug Moore) Subject: 2.3.3: template/operator- bug Message-ID: <9212280801.AA05912@cs.rice.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 28 Dec 1992 08:01:12 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 59