🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #73

Maybe a bug in G++ 1.35.1-.

#73
From: Bryan Boreham
Date: Tue, 20 Jun 1989 20:01
62 lines
1880 bytes
Here's the example:

extern "C" void printf(char *, ...);

class Point 
{
public:
  short x;
  short y;
  
public:
  Point(short xx, short yy)
    { x= xx; y= yy; }
  
  friend Point operator- (Point p1, Point p2)
    { return Point(p1.x - p2.x, p1.y - p2.y); }

};

void foo (Point p)
{
  printf("(%d, %d)\n", p.x, p.y);
}

main()
{
  Point x(10,20);
  Point y(30,40);

  foo (x - y);
}

Now, it compiles just fine:

kewill% g++ -v testpt.C -o testpt
g++ version 1.35.1-
 /usr/local/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 testpt.C /tmp/cca29165.cpp
GNU CPP version 1.35
 /usr/local/lib/gcc-cc1plus /tmp/cca29165.cpp -quiet -dumpbase testpt.C -noreg -version -o /tmp/cca29165.s
GNU C++ version 1.35.1- (68k, MIT syntax) compiled by GNU C version 1.35.
 as -mc68020 /tmp/cca29165.s -o testpt.o
 /usr/local/lib/gcc-ld++ -o testpt -C /usr/local/lib/crt0+.o /lib/Mcrt1.o testpt.o -lg++ /usr/local/lib/gcc-gnulib -lc

But, it gets the answer wrong!

kewill% testpt
(0, 40)

Now, I looked through Stroustrup and libg++, and I only ever see such
operators declared as:

	  friend Point operator- (Point& p1, Point& p2)

that is, with references instead of structures passed. So maybe there
is some reason why the answer is wrong.

Nonetheless, I think it ought to work.

Say, isn't ET++ good at flushing out those bugs?

Bryan.
Technical Details
Message-ID: <8906202001.AA29179@kewill.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!UUNET.UU.NET!kewill!bryan

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!UUNET.UU.NET!kewill!bryan
From: kewill!bryan@UUNET.UU.NET (Bryan Boreham)
Newsgroups: gnu.g++.bug
Subject: Maybe a bug in G++ 1.35.1-.
Message-ID: <8906202001.AA29179@kewill.uucp>
Date: 20 Jun 89 20:01:53 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 62