egcs-970929: Missing symbols
Kurt Garloff
garloff@kg1.ping.de
Thu Oct 2 01:29:00 GMT 1997
Hi egcs-hackers,
egcs-970929 (2.90.11) seems to swallow some code on my machine
(ix86-linux, glibc-2.0.5c, binutils-2.8.1.0.11) when using template
friend functions.
Here is some code:
garloff@kg1:~/numerix/egcs $ cat test.cc
/* test.cc */
/* demonstrates egcs++ bug */
/* K.Garloff@ping.de 97/10/02 */
#include <iostream.h>
template <class T>
class cplx
{
private:
T re, im;
public:
cplx () { re = 0; im = 0; };
cplx (const T r) { re = r; im = 0; }
cplx (const T r, const T i) { re = r; im = i; };
cplx (const cplx& c) { re = c.re; im = c.im; };
~cplx () {};
friend T real (const cplx<T>& c);
friend ostream& operator << (ostream&, const cplx<T>&);
};
template <class T>
T real (const cplx<T>& c)
{
return c.re;
};
template <class T>
ostream& operator << (ostream& ost, const cplx<T>& c)
{
ost << '(' << c.re;
if (c.im < 0) return ost << " - i" << -c.im << ')';
else return ost << " + i" << c.im << ')';
};
int main ()
{
cplx<double> cd (2, -1.5);
cout << real (cd) << '\n';
cout << cd << endl;
}
garloff@kg1:~/numerix/egcs $ g++ -c test.cc -fno-exceptions
compiles fine (the -fno-exceptions is just to keep a short symbol table),
but:
garloff@kg1:~/numerix/egcs $ nm test.o |c++filt
00000000 W cplx<double>::~cplx(void)
U __builtin_delete
U ostream::operator<<(ostream &(*)(ostream &))
U ostream::operator<<(char)
U ostream::operator<<(double)
U operator<<(ostream &, cplx<double> const &)
00000000 W cplx<double>::cplx(double, double)
U cout
U endl(ostream &)
00000000 t gcc2_compiled.
00000000 T main
U real(cplx<double> const &)
This will never link, because the two friend functions (operator << and
real) are entirely missing. I first thought that it is a name
(de)mangling bug, but I found (looking into assembly code), that it's not
only the symbols that are wrong or missing but there is no code at all
for ostream& operator << (ostream&, const cplx<double>&) nor for
double real (const cplx<double>&).
egcs-970917 (2.90.08) works well (2.90.10 as well, but it's not on this
machine):
garloff@kg1:~/numerix/egcs $ g++ -V egcs-2.90.08 -c test.cc -fno-exceptions
garloff@kg1:~/numerix/egcs $ nm test.o |c++filt
00000000 W cplx<double>::~cplx(void)
U __builtin_delete
U ostream::operator<<(char const *)
U ostream::operator<<(ostream &(*)(ostream &))
U ostream::operator<<(char)
U ostream::operator<<(double)
00000000 W operator<<(ostream &, cplx<double> const &)
00000000 W cplx<double>::cplx(double, double)
U cout
U endl(ostream &)
00000000 t gcc2_compiled.
00000000 T main
00000000 W real(cplx<double> const &)
----------------------------------------------------------------------
Kurt Garloff, Dortmund
<K.Garloff@ping.de>
More information about the Gcc-bugs
mailing list