Skip to content

CWG3067 [conv.array] Wording of array-to-pointer conversion #707

Description

@YurkoFlisk

Full name of submitter: Yuriy Prokopets

Reference (section label): conv.array

(I had a SO question about this a while ago, where the accepted answer by user17732522 agrees with me and gives some ideas for resolution, but there still was no issue submitted, so I decided to submit myself)

Issue description: the current wording for the section is:

An lvalue or rvalue 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 temporary materialization conversion ([conv.rval]) is applied. The result is a pointer to the first element of the array.

The problem is that it isn't clear what "the array" means. In particular, an expression to which the conversion is applied, despite having array type, may not denote an array (even if it is a glvalue). For example:

int a[5];
auto pa = reinterpret_cast<int(*)[5]>(&a[0]);

Here, since int and int[5] aren't pointer-interconvertible, the cast doesn't change the pointer-value, so *pa denotes not a, but the first element of a. So, if array-to-pointer conversion is applied to *pa, the wording, as is, explicitly intends to define the behaviour (unconditional "the result is", so this isn't a case of it being "undefined by omission"), but doesn't do so properly, because the meaning of "the array" is either completely unclear, or it could, for example, be interpreted in this case as "the containing array" of an object denoted by glvalue, though this is vague and most likely isn't intended interpretation.

Suggested resolution: rephrase the section like this:

An lvalue or rvalue expression E of type AR, which is an “array of N T” or “array of unknown bound of T”, can be converted to a prvalue of type “pointer to T”. The temporary materialization conversion ([conv.rval]) is applied. Let A be an object denoted by glvalue E (if E is a prvalue, the temporary materialization conversion ([conv.rval]) is applied first). The result is a pointer to the first element of the array A if its type is similar to AR, otherwise behaviour is undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions