This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Found possible bug in dynamic_cast
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Found possible bug in dynamic_cast
- From: Leif Lonnblad <leif at thep dot lu dot se>
- Date: Thu, 7 Oct 1999 15:44:38 +0200 (MET DST)
- Reply-To: Leif Lonnblad <leif at thep dot lu dot se>
Hi there,
the following simple program returns a non-zero exit status. As far as
I can tell from the C++ standard (Note however that I have only the
1997 C++ Public Review Document and Stroustrups third edition
available) it should return zero. Changing the order of the base
classes of foo (i.e. struct foo: public vbase, public base {...})
gives the expected behavior.
Cheers,
Leif
julio> g++ -v
Reading specs from /usr/local/egcs/lib/gcc-lib/i686-pc-linux-gnu/2.95.1/specs
gcc version 2.95.1 19990816 (release)
julio> g++ -E testdynamic.cc
# 1 "testdynamic.cc"
struct vbase {
virtual ~vbase(){}
};
struct base {
};
struct foo: public base, public vbase {
virtual ~foo() {}
};
struct bar: public foo {
virtual ~bar() {}
};
int main() {
bar * bp = new bar;
foo * fp = bp;
bar * bp2 = dynamic_cast<bar *>(fp);
if ( bp2 != bp ) return 1;
return 0;
}
julio> g++ testdynamic.cc
julio> a.out
julio> echo $status
1
julio>
--
--------------------------------------------------
Leif Lönnblad, Department of Theoretical Physics 2
Sölvegatan 14A, S-223 62 Lund, Sweden
phone: +46-46 2227780, fax: +46-46 2229686
e-mail: <Leif.Lonnblad@cern.ch>, <leif@thep.lu.se>
http://www.thep.lu.se/~leif