Title
Guarantees on casting pointer back to cv-qualified version of original type
Status
cd1
Section
7.6.1.9 [expr.static.cast]
Submitter
Mark Mitchell

Created on 2003-10-30.00:00:00 last changed 26 months ago

Messages

Date: 2005-04-15.00:00:00

[Voted into WP at April 2005 meeting.]

Date: 2022-02-18.07:47:23

Proposed resolution:

Change 7.6.1.9 [expr.static.cast] paragraph 10 as indicated:

A value of type pointer to object converted to "pointer to cv void" and back to the original pointer type, possibly with different cv-qualification, will have its original value. [Example:

  T* p1 = new T;
  const T* p2 = static_cast<const T*>(static_cast<void *>(p1));
  bool b = p1 == p2; // b will have the value true.

---end example]

Rationale: The wording "possibly with different cv-qualification" was chosen over the suggested wording to allow for changes in cv-qualification at different levels in a multi-level pointer, rather than only at the object type level.

Date: 2022-02-18.07:47:23

Paragraph 7.6.1.9 [expr.static.cast] paragraph 10 says that:

A value of type pointer to object converted to "pointer to cv void" and back to the original pointer type will have its original value.

That guarantee should be stronger. In particular, given:

  T* p1 = new T;
  const T* p2 = static_cast<const T*>(static_cast<void *>(p1));
  if (p1 != p2)
    abort ();
there should be no call to "abort". The last sentence of Paragraph 7.6.1.9 [expr.static.cast] paragraph 10 should be changed to read:

A value of type pointer to object converted to "pointer to cv void" and back to the original pointer type (or a variant of the original pointer type that differs only in the cv-qualifiers applied to the object type) will have its original value. [Example:
T* p1 = new T;
const T* p2 = static_cast<const T*>(static_cast<void *>(p1));
bool b = p1 == p2; // b will have the value true.
---end example.]
History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6691
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2005-10-22 00:00:00adminsetstatus: dr -> wp
2005-05-01 00:00:00adminsetmessages: + msg1187
2005-05-01 00:00:00adminsetstatus: ready -> dr
2004-11-07 00:00:00adminsetstatus: review -> ready
2004-04-09 00:00:00adminsetstatus: open -> review
2003-10-30 00:00:00admincreate