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

            Bug ID: 94565
           Summary: C++20: Comparing comparison category types against
                    0/nullptr is not noexcept
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.kruegler at googlemail dot com
  Target Milestone: ---

The following program should be accepted, but is rejected due to a violation of
the static_assertion:

Compiler options:

-Wall -Wextra -pedantic "-std=c++20"

//---------------------
#include <compare>

int main()
{
  static_assert(noexcept(std::partial_ordering::less == 0));
}
//---------------------

prog.cc: In function 'int main()':
prog.cc:5:17: error: static assertion failed
    5 |   static_assert(noexcept(std::partial_ordering::less == 0));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The corresponding comparison functions for are all declared as noexcept
([cmp.partialord], [cmp.weakord], [cmp.strongord]), so the clear intention is
that such an comparison should be observable as non-throwing operations. The
reason why above test fails for all of the existing mixed comparison functions
of all the three comparison category types against 0/nullptr is caused by the
fact that the implementation-internal type std::__cmp_cat::__unspec in header
<compare> misses to declare its converting constructor as noexcept:

struct __unspec
    {
      constexpr __unspec(__unspec*) { }
    };

Reply via email to