]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Constrain three-way comparison for std::optional [PR 98842]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 7 Jun 2021 12:02:15 +0000 (13:02 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 11 Jun 2021 22:23:56 +0000 (23:23 +0100)
commit4f11586945fffd0ff808c16f2f341f9e85d83749
treea93904cb99ab5a5b8345b8575951e4e4c7c66cd7
parent2ba1680d3e9f3bb99783519a08eed6435f131045
libstdc++: Constrain three-way comparison for std::optional [PR 98842]

The operator<=>(const optional<T>&, const U&) operator is supposed to be
constrained with three_way_comparable_with<U, T> so that it can only be
used when T and U are weakly-equality-comparable and also three-way
comparable.

Adding that constrain completely breaks std::optional comparisons,
because it causes constraint recursion. To avoid that, an additional
check that U is not a specialization of std::optional is needed. That
appears to be a defect in the standard and should be reported to LWG.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

PR libstdc++/98842
* include/std/optional (operator<=>(const optional<T>& const U&)):
Add missing constraint and add workaround for template
recursion.
* testsuite/20_util/optional/relops/three_way.cc: Check that
type without equality comparison cannot be compared when wrapped
in std::optional.

(cherry picked from commit adec14811714e22a6c1f7f0199adc05370f0d8b0)
libstdc++-v3/include/std/optional
libstdc++-v3/testsuite/20_util/optional/relops/three_way.cc