Title
Problems in specifying pointer conversions
Status
cd3
Section
7.6.1.9 [expr.static.cast]
Submitter
Nikolay Ivchenkov

Created on 2011-11-01.00:00:00 last changed 90 months ago

Messages

Date: 2013-04-15.00:00:00

[Moved to DR at the April, 2013 meeting.]

Date: 2012-02-15.00:00:00

Proposed resolution (February, 2012):

  1. Change 7.3.12 [conv.ptr] paragraph 2 as follows:

  2. A prvalue of type “pointer to cv T,” where T is an object type, can be converted to a prvalue of type “pointer to cv void”. The result of converting a “pointer to cv T non-null pointer value of a pointer to object type to a “pointer to cv void” points to the start of the storage location where the object of type T resides, as if the object is a most derived object (6.7.2 [intro.object]) of type T (that is, not a base class subobject) represents the address of the same byte in memory as the original pointer value. The null pointer value is converted to the null pointer value of the destination type.
  3. Change 7.6.1.9 [expr.static.cast] paragraph 13 as follows:

  4. A prvalue of type “pointer to cv1 void” can be converted to a prvalue of type “pointer to cv2 T,” where T is an object type and cv2 is the same cv-qualification as, or greater cv-qualification than, cv1. The null pointer value is converted to the null pointer value of the destination type. If the original pointer value represents the address A of a byte in memory and A satisfies the alignment requirement of T, then the resulting pointer value represents the same address as the original pointer value, that is, A. The result of any other such pointer conversion is unspecified. A value of type pointer to object converted to “pointer to cv void” and back, possibly with different cv-qualification, shall have its original value...
  5. Change 7.6.1.10 [expr.reinterpret.cast] paragraph 7 as follows:

  6. An object pointer can be explicitly converted to an object pointer of a different type.70 When a prvalue v of object pointer type “pointer to T1 is converted to the object pointer type “pointer to cv T2”, the result is static_cast<cv T2*>(static_cast<cv void*>(v)) if both T1 and T2 are standard-layout types (6.8 [basic.types]) and the alignment requirements of T2 are no stricter than those of T1, or if either type is void. Converting a prvalue of type “pointer to T1” to the type “pointer to T2” (where T1 and T2 are object types and where the alignment requirements of T2 are no stricter than those of T1) and back to its original type yields the original pointer value. The result of any other such pointer conversion is unspecified.
Date: 2012-02-27.00:00:00

The definedness of various pointer conversions (see 7.6.1.10 [expr.reinterpret.cast] paragraph 7, 11.4 [class.mem] paragraph 20, 7.6.1.9 [expr.static.cast] paragraph 13) relies on the properties of the types involved, such as whether they are standard-layout types and their intrinsic alignment. This creates contradictions and unnecessary unspecified behavior when the actual values of the pointer involved would actually permit the operations. Recasting the specification in terms of the memory model instead of the types of the objects provides a more coherent specification.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-05-03 00:00:00adminsetmessages: + msg4384
2013-05-03 00:00:00adminsetstatus: ready -> dr
2012-11-03 00:00:00adminsetstatus: review -> ready
2012-02-27 00:00:00adminsetmessages: + msg3752
2012-02-27 00:00:00adminsetstatus: open -> review
2011-11-01 00:00:00admincreate