C++ Logo

sg12

Advanced search

Re: [isocpp-lib-ext] Total order for pointer comparisons (again)

From: Herring, Davis <herring_at_[hidden]>
Date: Mon, 27 Nov 2023 21:18:59 +0000
> I'm wondering if there has been a conclusion to it, and especially if > there's some appetite for (finally) having language comparison operators > always establish a total order between pointers. It doesn't much affect the design question here, but there's an issue with the framing: the "implementation-defined strict total order over pointers" ([defns.order.ptr]) claims to be "over all pointer values", but std::less and friends are of course limited to comparing _addresses_. They therefore fail to distinguish, say, a pointer to an array from a pointer to its first element, or a pointer past an object from a pointer to the next object <https://godbolt.org/z/sYeseM8r8>. (Note that this example is fragile, thanks to stack layout and questionable constant folding.) We will need to rephrase the implementation-defined order to be over addresses, being careful not to accidentally introduce the very issue of memory linearity by suggesting that those addresses are just the results of memcpy-ing the pointer into an integer. Davis PS - Having written this up, I'll file a Library issue presently.

Received on 2023-11-27 21:19:11