Title
static_cast from "pointer to void" does not handle similar types
Status
cd6
Section
7.6.1.9 [expr.static.cast]
Submitter
Richard Smith

Created on 2022-06-28.00:00:00 last changed 20 months ago

Messages

Date: 2022-07-01.20:56:37

Proposed resolution (approved by CWG 2022-07-01):

Change in 7.6.1.9 [expr.static.cast] paragraph 13 as follows:

... Otherwise, if the original pointer value points to an object a, and there is an object b of type similar to T (ignoring cv-qualification) that is pointer-interconvertible (6.8.4 [basic.compound]) with a, the result is a pointer to b. Otherwise, the pointer value is unchanged by the conversion.
Date: 2022-07-15.00:00:00

[Accepted at the July, 2022 meeting.]

Consider:

  struct S {
    int a[5];
  } s;
  int (*p)[] = reinterpret_cast<int(*)[]>(&s);
  int n = (*p)[0];

This ought to have defined behavior: a pointer to s and a pointer to s.a are pointer-interconvertible, so you should be able to navigate between them this way. But the cast as shown does not work, because the type of the pointer-interconvertible object is int[5], not int[].

History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: ready -> cd6
2022-07-01 20:56:37adminsetstatus: open -> ready
2022-06-30 16:25:58adminsetmessages: + msg6874
2022-06-28 00:00:00admincreate