Variation on the type punning theme: in-place trivial construction
It is undefined behavior to use the result of promote
as an array. If we look at [expr.add]/4.2 we have
Otherwise, if
P
points to an array elementi
of an array objectx
withn
elements ([dcl.array]), the expressionsP + J
andJ + P
(whereJ
has the valuej
) point to the (possibly-hypothetical) array elementi+j
ofx
if0≤i+j≤n
and the expressionP - J
points to the (possibly-hypothetical) array elementi−j
ofx
if0≤i−j≤n
.
we see that it requires the pointer to actually point to an array object. You don't actually have an array object though. You have a pointer to a single Pixel
that just happens to have other Pixels
following it in contiguous memory. That means the only element you can actually access is the first element. Trying to access anything else would be undefined behavior because you are past the end of the valid domain for the pointer.