According to conv.array, array-to-pointer conversion is defined like this (bold emphasis mine):
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
This wording seems to assume that expression, subject to the conversion, refers to an array which is implicitly understood to be the one referred to by emphasized "the array". However, this is not necessarily the case since it's legally possible, e.g., to have lvalue of type T[N]
referring to object of type T
:
int a[5];
auto pa = reinterpret_cast<int(*)[5]>(&a[0]);
Now, *pa
is lvalue of type int[5]
, but refers to int
object (the first element of a
) since during reinterpret_cast
pointer-value was unchanged due to int[5]
and int
being not pointer-interconvertible types. Note that, on the other hand, *std::launder(pa)
is an expression of type int[5]
referring to int[5]
object at the address represented by pa
(i.e., a
), so array-to-pointer conversion would apply to it in an obvious way if needed, e.g., by subscript operator. However, applying the conversion to *pa
(which applies because expression type is appropriate) results in lack of obvious interpretation of what "the array" from above wording means in this case (and, thus, what resulting pointer points to). In this answer (to question about whether T*
and T(*)[N]
are pointer-interconvertible), where such situation arises, it's interpreted that behaviour is undefined by omission, however as explained above the quoted paragraph does apply and defines behaviour ("The result is" provided regardless of something like "if the expression refers to array", such condition is absent from wording), but meaning of "the array" is unclear.
So, is in this case
- behaviour indeed undefined per current wording contrary to my observations (if yes, why),
- defined in some non-obvious way (if yes, in which way),
- the wording is imprecise?