🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Overloaded const bug.

#625
From: Dave Newton
Date: Mon, 27 Nov 1989 21:41
51 lines
2091 bytes

/*

Overloaded const Bug?

The program below declares t1::fun() as a const member and t2::fun() as an overloaded
nonconst member. In the main program when "fun()" is called directly everythings
works as I expected. However when "fun()" is call via the member function 
"t1:dave()" "t1:fun()" get called instead of "t2:fun()".
*/

#include <stream.h>

class t1 {
public:
  virtual const char* fun() const;
  void dave();
};

const char* t1::fun() const {cout << "t1:fun()\n"; return NULL;}
void t1::dave() {fun();}

class t2: public t1 {
public:
  const char* fun();
};

const char* t2::fun() {cout << "t2:fun()\n"; return NULL;}

main() {
  t2 a;
  a.fun();   // prints t2:fun()
  a.dave();  // prints t1:fun(). I expected t2:fun() to be printed since
             // a is not a const object.
}
 
/*
Machine: SUN3 Operating System V4.02
Compiler Information:

g++ -v  -o test test.cc 
gcc version 1.36.1 (based on GCC 1.36)
 /usr/local/gnu/1.36/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 test.cc /usr/tmp/cca02573.cpp
GNU CPP version 1.36
 /usr/local/gnu/1.36/lib/gcc-cc1plus /usr/tmp/cca02573.cpp -quiet -dumpbase test.cc -version -o /usr/tmp/cca02573.s
GNU C++ version 1.36.1 (based on GCC 1.36) (68k, MIT syntax) compiled by GNU C version 1.36.
default target switches: -m68020 -mc68020 -m68881 -mbitfield
test
 /usr/local/gnu/1.36/lib/gcc-as -mc68020 -o test.o /usr/tmp/cca02573.s
 /usr/local/gnu/1.36/lib/gcc-ld -o test -e start -dc -dp /lib/crt0.o /lib/Mcrt1.o test.o -lg++ /usr/local/gnu/1.36/lib/gcc-gnulib -lc
Technical Details
Message-ID: <8911272141.AA02580@suntrek.cad.mcc.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!MCC.COM!newton%cadillac.cad.mcc.com

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!MCC.COM!newton%cadillac.cad.mcc.com
From: newton%cadillac.cad.mcc.com@MCC.COM (Dave Newton)
Newsgroups: gnu.g++.bug
Subject: Overloaded const bug.
Message-ID: <8911272141.AA02580@suntrek.cad.mcc.com>
Date: 27 Nov 89 21:41:12 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 51