Created on 2023-08-23.00:00:00 last changed 1 month ago
Subclause 7.6.10 [expr.eq] bullet 3.1 specifies:
- If one pointer represents the address of a complete object, and another pointer represents the address one past the last element of a different complete object, [ Footnote: ... ] the result of the comparison is unspecified.
This phrasing does not properly handle the case where addresses of subobjects are compared, yet those subobjects happen to have the same address as their respective complete objects.
The rule in question was introduced by issue 1652 for purposes of constant evaluation: comparing a pointer to an object X with a pointer past the end of another object Y ought not to be possible during contant evaluation. However, that issue resolution also caused a change to runtime behavior, departing from the prior "address comparison" model. It turns out that implementations nowadays rely on that rule for optimization purposes (see the reflector discussion).
Change in 7.6.10 [expr.eq] bullet 3.1 as follows:
- If one pointer represents the address of
acomplete object, and another represents the address one past the last element of a differentcomplete object, the result of the comparison is unspecified.