This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 113d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-03-20


799. Can reinterpret_cast be used to cast an operand to its own type?

Section: 7.6.1.10  [expr.reinterpret.cast]     Status: CD2     Submitter: UK     Date: 3 March, 2009

N2800 comment UK 55

[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):

  1. Change 7.6.1.10 [expr.reinterpret.cast] paragraph 2 as follows:

  2. 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.
  3. Change 7.6.1.10 [expr.reinterpret.cast] paragraph 10 as follows:

  4. An rvalue of type “pointer to member of X of type T1” can be explicitly converted to an rvalue of a different type “pointer to member of Y of type T2” if T1 and T2 are both function types or both object types...