int a = reinterpret_cast<int>(-1);
source.cpp(3): error C2440: 'reinterpret_cast' : cannot convert from 'int' to 'int'
Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast
@yumetodo §5.2.10 p2により整数型を自分自身の型にキャストすることは合法。— Ryou Ezoe (@EzoeRyou) 2016年5月11日
The reinterpret_cast operator shall not cast away constness (5.2.11). An expression of integral, enumeration, pointer, or pointer-to-member type can be explicitly converted to its own type; such a cast yields the value of its operand.
dynamic_cast and reinterpret_cast,crossreference 5.2.11 without creating an extra note. The,second half of the note is unrelated to the crossrefernce,,and would serve as well in normative text.
Strike the note,about definition of casting away constness, preserve the,cross-reference. The second sentance on reintrepret_cast to,its own type should move out of the note into the normative,text.
ACCEPTED,The repetition of the reference to 5.2.11 was handled as a quasi-editorialchange in paper N2841.,Issue 799 was opened for the question about castingto the same type as the operand.,See paper,N2841
たしかにイギリスからNational Body commentsとして出ていて、
799. Can reinterpret_cast be used to cast an operand to its own type?
Section: 5.2.10 [expr.reinterpret.cast] Status: CD2 Submitter: UK Date: 3 March, 2009
[Voted into WP at March, 2010 meeting.]
The note in 5.2.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
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 5.2.10 [expr.reinterpret.cast] paragraph 2 as follows:
reinterpret_castoperator shall not cast away constness (5.2.11 [expr.const.cast]).
[Note: Subject to the restrictions in this section, an expression may be cast to its own type using aAn 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.
reinterpret_castoperator. —end note]
Change 5.2.10 [expr.reinterpret.cast] paragraph 10 as follows:
An rvalue of type “pointer to member of
T1” can be explicitly converted to an rvalue of a different type “pointer to member of
T2are both function types or both object types...