Title
Array-to-pointer conversion with object type mismatch
Status
ready
Section
7.3.3 [conv.array]
Submitter
Andrey Erokhin

Created on 2020-10-28.00:00:00 last changed 1 month ago

Messages

Date: 2025-11-05.18:54:12

Proposed resolution (approved by CWG 2025-11-05):

Change in 7.3.3 [conv.array] as follows:

An lvalue or rvalue expression E of type “array of N T” or “array of unknown bound of T” can be converted to a prvalue of type “pointer to T”. The If E is a prvalue, the temporary materialization conversion (7.3.5 [conv.rval]) is applied. The If the result of E (possibly converted) is an object whose type is similar to the type of E, the result is a pointer to the first element of the array; otherwise, the behavior is undefined.
Date: 2025-11-05.18:54:12

(From submission #707.)

Consider:

  int a[5];
  int *p1 = &a[0];        // points to the first element of a
  auto pa = reinterpret_cast<int(*)[5]>(p1);
  int *p2 = *pa;              // valid array-to-pointer conversion?

If a glvalue of array type is subject to the array-to-pointer conversion, the behavior should be undefined if the type of the result of the glvalue is not an array (see 7.6.1.5 [expr.ref] paragraph 10 for the class member access case).

History
Date User Action Args
2025-11-07 07:33:50adminsetstatus: tentatively ready -> ready
2025-11-05 18:54:12adminsetmessages: + msg8219
2025-11-05 18:54:12adminsetstatus: open -> tentatively ready
2020-10-28 00:00:00admincreate