The following program returns 1 instead of 0 because gcc seems not to do a
static_cast followed by a const_cast when doing the C-style cast. This is in
violation of 5.4 of the standard.

The problem first appeared in gcc 4.0.0. Here is the -v output of the version I
am currently using:

Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls
--without-included-gettext --enable-threads=posix --program-suffix=-4.0
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --enable-mpfr
--disable-werror --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.1 20050617 (prerelease) (Debian 4.0.0-10)

-----------------------------------------------------------------------------

struct A
{
  int a;
};

struct B
{
  int b;
};

struct C: public A, public B
{
};

int
main()
{
  C c;
  const C *cptr = &c;
  B* bad  = (B*)cptr;
  B* good = const_cast<B*>(static_cast<const B *>(cptr));
  return bad != good;
}

-- 
           Summary: C-Style cast does reinterpret_cast when it should do a
                    static_cast
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gccbug at gammarayburst dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i686-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22281

Reply via email to