Bug 23418 - old-style cast uses reinterpret+const instead of static+const
Summary: old-style cast uses reinterpret+const instead of static+const
Status: RESOLVED DUPLICATE of bug 22132
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-16 09:59 UTC by Stephan Bergmann
Modified: 2005-08-16 11:56 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Bergmann 2005-08-16 09:59:42 UTC
In the program

  #include <stdio.h>
  struct Base1 { int x1; };
  struct Base2 { int x2; };
  struct Derived: public Base1, public Base2 {};
  int main() {
    Derived const * d = new Derived;
    printf("%p %p %p\n", d, (Base2 *) d, (Base2 const *) d);
  }

the cast "(Base2 *) d" effectively does a

  const_cast< Base2 * >(reinterpret_cast< Base2 const * >(d))

instead of a

  const_cast< Base2 * >(static_cast< Base2 const * >(d))

(with the effect that of the three printed pointer values, errouneously the
first two are identical instead of the last two).  This is in violation of 5.4/5
of the C++ Standard.

This happens with both 4.0.0 and 4.0.1, but not with 3.4.3.  This error affects
the OpenOffice.org code base.
Comment 1 Andrew Pinski 2005-08-16 11:56:46 UTC
This has already been fixed in 4.0.2.
This is a dup of bug 22132.

*** This bug has been marked as a duplicate of 22132 ***