This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/23418] New: old-style cast uses reinterpret+const instead of static+const
- From: "stephan dot bergmann at sun dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Aug 2005 09:59:44 -0000
- Subject: [Bug c++/23418] New: old-style cast uses reinterpret+const instead of static+const
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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.
--
Summary: old-style cast uses reinterpret+const instead of
static+const
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: stephan dot bergmann at sun dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23418