From: bjornw@colargol.ai.mit.EDU (Bjoern Wennberg)
Subject: Bug in g++-3.2.1.
Organization: Colargol, Trondheim College of Engineering
Distribution: gnu
Date: Tue, 10 Nov 1992 18:56:22 GMT

GCC VERSION 2.3.1

OS: Interactive-3.0 SYSVR3.2

MACHINE: 486 pc

PROBLEM:
  gcc-2.3.1 does not generate (enough!!!) code for the following example
  while gcc-2.2.2 does:

---
#include <iostream.h>

class foo {
  char text[30];
public:
  foo() { strcpy(text, "This is a test"); }
  friend ostream& operator << (ostream& s, foo& f)
  {
    return s << f.text;
  }
};

foo bar;
int main(void)
{
  cout << bar;
}

----

When compiled this program with gcc-2.3.1 I get:

epsilon:~/skole/algmet/oving5# g++ -v c.c
Reading specs from /usr/local/lib/gcc-lib/isc/2.3.1/specs
gcc version 2.3.1
 /usr/local/lib/gcc-lib/isc/2.3.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dunix -Di386 -D__unix__ -D__i386__ -D__unix -D__i386 c.c /usr/tmp/cca02369.i
GNU CPP version 2.3.1 (80386, ATT syntax)
 /usr/local/lib/gcc-lib/isc/2.3.1/cc1plus /usr/tmp/cca02369.i -quiet -dumpbase c.cc -version -o /usr/tmp/cca02369.s
GNU C++ version 2.3.1 (80386, ATT syntax) compiled by GNU C version 2.2.2.
 as -o /usr/tmp/cca023691.o /usr/tmp/cca02369.s
 ld /lib/crt1.o /usr/local/lib/gcc-lib/isc/2.3.1/crtbegin.o -L/usr/local/lib/gcc-lib/isc/2.3.1 -L/usr/local/lib /usr/tmp/cca023691.o -lg++ -lgcc -lc -lg -lgcc /usr/local/lib/gcc-lib/isc/2.3.1/crtend.o /lib/crtn.o
undefined                       first referenced
 symbol                             in file
__ls__FR7ostreamR3foo               /usr/tmp/cca023691.o
ld fatal: Symbol referencing errors. No output written to a.out
epsilon:~/skole/algmet/oving5# 

Here is the output from gcc-2.2.2:
Reading specs from /global/gnu/lib/gcc-lib/isc/2.2.2/specs
gcc version 2.2.2
 /global/gnu/lib/gcc-lib/isc/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dunix -Di386 -D__unix__ -D__i386__ -D__unix -D__i386 c.c /usr/tmp/cca02374.i
GNU CPP version 2.2.2 (80386, ATT syntax)
 /global/gnu/lib/gcc-lib/isc/2.2.2/cc1plus /usr/tmp/cca02374.i -m486 -quiet -dumpbase c.cc -version -o /usr/tmp/cca02374.s
GNU C++ version 2.2.2 (80386, ATT syntax) compiled by GNU C version 2.2.2.
 as -o c.o /usr/tmp/cca02374.s
 ld /lib/crt1.o /global/gnu/lib/gcc-lib/isc/2.2.2/crtbegin.o -L/global/gnu/lib/gcc-lib/isc/2.2.2 -L/global/gnu/lib c.o -lg++ -lgcc -lc -lg -lgcc /global/gnu/lib
/gcc-lib/isc/2.2.2/crtend.o /lib/crtn.o
epsilon:~/skole/algmet/oving5# a.out
This is a test

The assembler files produced by gcc-2.3.1 does not contain any code
for the overloaded ostream operator <<. 

g++-2.3.1 -S c.c produces this peace of code:

        .file   "c.c"
gcc2_compiled.:
text
LC0:
        .byte 0x54,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20
        .byte 0x74,0x65,0x73,0x74,0x0
        .align 4
__3foo:
        pushl %ebp
        movl %esp,%ebp
        pushl %ebx
        movl 8(%ebp),%ebx
        pushl $.LC0
        pushl %ebx
        call strcpy
        addl $8,%esp
L228:
        movl %ebx,%eax
        jmp .L227
        .align 4
        jmp .L227
        .align 4
L227:
        movl -4(%ebp),%ebx
        leave
        ret
globl bar
data
bar:
        .set .,.+30
text
        .align 4
globl main
main:
        pushl %ebp
        movl %esp,%ebp
        pushl $bar
        pushl $cout
        call __ls__FR7ostreamR3foo
        addl $8,%esp
        xorl %eax,%eax
        jmp .L229
        .align 4
        jmp .L229
        .align 4
L229:
        leave
        ret
        .align 4
globl _GLOBAL_.I.bar
_GLOBAL_.I.bar:
        pushl %ebp
        movl %esp,%ebp
        pushl $bar
        call __3foo
        addl $4,%esp
L230:
        leave
        ret
        .section .init,"x"
        pushl $_GLOBAL_.I.bar



bjornw>
Bjoern.Wennberg@colargol.edb.tih.no
--
The sooner all the animals are dead, the sooner we'll find all their money.

Newsgroups: gnu.g++.bug