This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/28357] [4.0/4.1/4.2 regression] c-style downcasts on const multiple inherited objects differ if const vs non-const cast
- From: "mmitchel at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Jul 2006 03:59:49 -0000
- Subject: [Bug c++/28357] [4.0/4.1/4.2 regression] c-style downcasts on const multiple inherited objects differ if const vs non-const cast
- References: <bug-28357-8961@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from mmitchel at gcc dot gnu dot org 2006-07-20 03:59 -------
I do not believe this is a bug. The problematic conversion is:
SdOptionsPrint &rOldUnconst = (SdOptionsPrint&)(rOther);
Here, rOther is declared as:
const SdOptionsPrintItem &rOther
and SdOptionsPrintItem is derived from SdOptionsPrint.
In the current WP, the first option for static_cast is casting an lvalue of
type cv1 B to cv2 D, where D is derived from B. This case does not apply; we
are casting from derived to base, not base to derived. The second option is a
converion as if:
SdOptionsPrint &t(rOther);
However, that conversion is not valid, as it casts aways const-ness.
(Therefore, the reference cannot be bound directly to the object referred to by
rOther, and since the reference is not to a const non-volatile type, we are not
allowed to create a temporary.) There are then several other options, none of
which apply.
Therefore, this case is in fact a reinterpret_cast.
--
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28357