[C++ 20] how to use the 3-way comparison operator (Space Ship Operator)?

hi

#include <compare>
#include <cstdlib>

int main (void)
{
  float f = 0x1p63f;
  unsigned long long int u = (1ULL << 63) + 1;

  if ((f <=> u) >= 0)
    abort ();

  if ((u <=> f) <= 0)
    abort ();
}

You need to add the command-line option -std=c++20 or -std=gnu++20, the default is gnu++14 which is C++14 with support for GCC extensions.

Additionally, it seems like the compiler explorer version of armv8 clang is missing a newer libstdc++ and has a broken libc++ because it can’t compile with any options.

It works fine with -std=c++20 on x86-64 (and it works with -stdlib=libc++ as well).

Thanks @TNorthover and @tobiashieta very much for detail usage