C++ Logo

std-discussion

Advanced search

Re: Hostile implementation of strict total order of pointers

From: David Brown <david.brown_at_[hidden]>
Date: Sun, 23 Jul 2023 17:32:55 +0200
On 22/07/2023 20:40, Lénárd Szolnoki via Std-Discussion wrote:
> Hi,
>
> Given these two arrays, each being a complete object:
>
> int a[2];
> int b[2];
>
> The partial ordering of the addresses (defined by the operator <) of
> the int objects within is:
>
> 1. &a[0] < &a[1]
> 2. &b[0] < &b[1]
>
> A hostile strict total order that is consistent with this is
> &a[0] < &b[0] < &a[1] < &b[1].
>
> Is there wording that prevents the implementation defined strict total
> order to manifest like this?
>

Arrays have to be contiguous, due to the way the [] operator works. Two
objects cannot overlap (unless one is a base-class or sub-object of the
other, or at least one has "no_unique_address"). I think that rules out
any possibility of such as a "hostile" ordering.


> One problem with this is that std::less is commonly used to check if a
> given pointer points within a range. If such a manifestation is
> possible then such usages are incorrect (or at least theoretically not
> portable).
>
> Cheers,
> Lénárd
>
> P.S. Someone pointed this out to me on the #include <C++> discord.

Received on 2023-07-23 15:33:15