C++ Logo

std-discussion

Advanced search

Re: std::less, tuple, pointer ordering

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Tue, 30 Jun 2020 13:54:53 +0300
On Tue, 30 Jun 2020 at 13:37, Giuseppe D'Angelo via Std-Discussion
<std-discussion_at_[hidden]> wrote:
> > For users, I'm fine with their custom wrappers calling < on pointers, because it is implementation defined, and fine. The code you posted is probably defined on all platforms that Qt supports.
>
> I didn't want to get there right away... In principle I could also be
> happy if an implementation provided a strong guarantee that operator< on
> pointers gives a total order (e.g. some constant/macro in a standard
> header so I could static_assert on it). But that is a complete
> non-starter: both GCC and MSVC already optimize away code based on
> unspecified pointer comparisons:

Indeed. That ship sailed while we were happily sleeping thinking "no
compiler will ever do that".
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78420
We ended up using the pre-c++20 builtin almost-equivalent of
is_constant_evaluated to fix std::less.

If you're still thinking that comparing pointers is "fine for all
relevant platforms", wake up. The compilers
walked through the wide-open unspecified-door years ago.

Received on 2020-06-30 05:58:18