This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Found possible bug in dynamic_cast


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]