CWG Issue 799 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-11-05
799. Can reinterpret_cast be used to cast an operand to its own type?
Section: 7.6.1.10 [expr.reinterpret.cast]Status: CD2Submitter: UKDate: 3 March, 2009
[Voted into WP at March, 2010 meeting.]
The note in 7.6.1.10 [expr.reinterpret.cast] paragraph 2 says,
Subject to the restrictions in this section, an expression may be cast to its own type using a reinterpret_cast operator.
However, there is nothing in the normative text that permits this conversion, and paragraph 1 forbids any conversion not explicitly permitted.
(See also issue 944.)
Proposed resolution (October, 2009):
- Change 7.6.1.10 [expr.reinterpret.cast] paragraph 2 as follows:
The reinterpret_cast operator shall not cast away constness (7.6.1.11 [expr.const.cast]).
[Note: Subject to the restrictions in this section, an expression may be cast to its own type using a reinterpret_cast operator. —_end note_]An expression of integral, enumeration, pointer, or pointer-to-member type can be explictly converted to its own type; such a cast yields the value of its operand.
- Change 7.6.1.10 [expr.reinterpret.cast] paragraph 10 as follows:
An rvalue of type “pointer to member of X of typeT1” can be explicitly converted to an rvalue of a different type “pointer to member of Y of typeT2” if T1 and T2 are both function types or both object types...