🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

GNU C++ bug report

#257
From: Wolfgang Laun
Date: Tue, 14 Apr 1992 10:56
70 lines
2823 bytes
#! /bin/sh
# Bug report for GNU C++

# This is how I compiled:
cat <<XXX >wlbug.log

g++ version 1.37.1 (based on GCC 1.37)
 /usr/local/gnu/sun4/lib/gcc-cpp -+ -v -I/usr/local/gnu/sun4/lib/g++-include -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ bug1.cc /usr/tmp/cca04454.cpp
 GNU CPP version 1.37.1
 /usr/local/gnu/sun4/lib/gcc-cc1plus /usr/tmp/cca04454.cpp -quiet
-dumpbase bug1.cc -version -o /usr/tmp/cca04454.s
GNU C++ version 1.37.1 (based on GCC 1.37) (sparc) compiled by GNU C
version 1.37.1.
default target switches: -mfpu -mepilogue
 /usr/local/gnu/sun4/lib/gcc-as -o bug1.o /usr/tmp/cca04454.s
 /usr/local/gnu/sun4/lib/gcc-ld -o bug1 -e start -dc -dp /lib/crt0.o -L/usr/local/gnu/sun4/lib bug1.o -lg++ -lg++ /usr/local/gnu/sun4/lib/gcc-gnulib -lc

XXX
# This is the complete source file:
cat <<XXX >wlbug.cc
#include <ostream.h>

class Rational {
  int E, D;
public:
  Rational() {};
  Rational( int enu, int den = 1 ): E(enu), D(den) {}
  operator double(){ return (double)E/D; }
  friend Rational operator +( Rational r1, Rational r2 );
  friend ostream& operator <<( ostream& s, Rational r );
};

Rational operator +( Rational r1, Rational r2 ){
  return Rational( r1.E*r2.D + r1.D*r2.E, r1.D*r2.D );
}

ostream& operator <<( ostream& s, Rational r ){
  return s << r.E << "/" << r.D;
}

int main() {
  Rational a(2), b(1,2), c;
  c = a + b;
  cout << a << " + " << b << " = " << c << "\n";
}
XXX

# Operating System is SunOS 4.xx
# Sparc Station

# Description of error:
cat <<XXX >wlbug.description
Depending on the presence of the conversion operator "double" in
class Rational, default assignment (together with the default copy
constructor?) appears to select a weird way:
a) convert rhs to double
b) convert rhs to int
c) construct a Rational from this int, using default for den
d) assign rhs to lhs

Defining a Rational& operator =( Rational r ) and the copy constructor
will also bypass the problem.
XXX
exit
--
           V             Wolfgang Laun         C=AT;A=ADA;P=Alcatel-W01 (X.400)
+---------------------+  Software Trainer                  <laun@alcatel.co.at>
| A  L  C  A  T  E  L |  Alcatel Austria AG               DVAX01::ED_LAUN (ANS)
+---------------------+  Scheydgasse 41                  +43-1-27722-2662 (tel)
     A U S T R I A       A-1210 Vienna, Austria/Europe   +43-1-27722-188  (fax)
Technical Details
Message-ID: <9204140656.AA29189@alcatel.co.at>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!alcatel.co.AT!laun

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!alcatel.co.AT!laun
From: laun@alcatel.co.AT (Wolfgang Laun)
Subject: GNU C++ bug report
Message-ID: <9204140656.AA29189@alcatel.co.at>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 14 Apr 1992 10:56:12 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 71