On Sunday, September 9, 2018 at 6:35:34 AM UTC-4, Ben Bacarisse wrote:
...
> Since I imagine that out-of-bounds access is described as resulting in
> undefined behaviour, either explicitly or implicitly through a violated
> "shall", it does not result in the program being ill-formed.
>
> (I'm not as familiar with the C++ standard as I am with the C one so I
> am feeling my way here.)
The two standards say this is pretty much the same way:
Re: pointer + integer:
"If both the pointer operand and the result point to elements of the
same array object, or one past the last element of the array object, the
evaluation shall not produce an overflow; otherwise, the behavior is
undefined. If the result points one past the last element of the array
object, it shall not be used as the operand of a unary * operator that
is evaluated." (C 6.5.6p8).
"If both the pointer operand and the result point to elements of the
same array object, or one past the last element of the array object, the
evaluation shall not produce an overflow; otherwise, the behavior is
undefined." (C++ 5.7p4)
However, the last sentence of the C 6.5.6p8 doesn't seem to have a
corresponding clause in the C++ standard, which surprises me.