[Bug libstdc++/78420] [6/7/8 Regression] std::less<T*> is not a total order with -O2 enabled

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 13 22:08:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78420

--- Comment #27 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Here's a really horrible case:

#include <functional>
#include <cassert>

struct X {
  operator const X*() const { return this; }
};

X x;
X y;

int main()
{
  std::less<> lt;
  bool x_less_than_y = lt(x, y);
  bool y_less_than_x = lt(y, x);
  bool x_equal_to_y = !lt(x, y) && !lt(y, x);
  assert( ((int)x_less_than_y + (int)y_less_than_x + (int)x_equal_to_y) == 1 );
}

This happens to give the right answer today, but I don't trust it to always do
so. We can't dispatch to the special case for pointers that casts to uintptr_t
because we can't know that we'll be comparing pointers (without
std::experimental::invocation_type at least ... so I guess I finally have a use
case for that).


More information about the Gcc-bugs mailing list