diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-03-27 15:24:05 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-05-07 13:46:11 +0100 |
commit | b72e7addf855aed66c0922f17efc85f26193f801 (patch) | |
tree | eedb5a1e728233d8c6fb4a91fbadf3f486b96405 /gcc/expr.cc | |
parent | 9ebd123432873edf1551006be07381150fd617ea (diff) | |
download | gcc-b72e7addf855aed66c0922f17efc85f26193f801.zip gcc-b72e7addf855aed66c0922f17efc85f26193f801.tar.gz gcc-b72e7addf855aed66c0922f17efc85f26193f801.tar.bz2 |
libstdc++: Constrain equality ops for std::pair, std::tuple, std::variant
Implement the changes from P2944R3 which add constraints to the
comparison operators of std::pair, std::tuple, and std::variant.
The paper also changes std::optional, but we already constrain its
comparisons using SFINAE on the return type. However, we need some
additional constraints on the [optional.comp.with.t] operators that
compare an optional with a value. The paper doesn't say to do that, but
I think it's needed because otherwise when the comparison for two
optional objects fails its constraints, the two overloads that are
supposed to be for comparing to a non-optional become the best overload
candidates, but are ambiguous (and we don't even get as far as checking
the constraints for satisfaction). I reported LWG 4072 for this.
The paper does not change std::expected, but probably should have done.
I'll submit an LWG issue about that and implement it separately.
Also add [[nodiscard]] to all these comparison operators.
libstdc++-v3/ChangeLog:
* include/bits/stl_pair.h (operator==): Add constraint.
* include/bits/version.def (constrained_equality): Define.
* include/bits/version.h: Regenerate.
* include/std/optional: Define feature test macro.
(__optional_rep_op_t): Use is_convertible_v instead of
is_convertible.
* include/std/tuple: Define feature test macro.
(operator==, __tuple_cmp, operator<=>): Reimplement C++20
comparisons using lambdas. Add constraints.
* include/std/utility: Define feature test macro.
* include/std/variant: Define feature test macro.
(_VARIANT_RELATION_FUNCTION_TEMPLATE): Add constraints.
(variant): Remove unnecessary friend declarations for comparison
operators.
* testsuite/20_util/optional/relops/constrained.cc: New test.
* testsuite/20_util/pair/comparison_operators/constrained.cc:
New test.
* testsuite/20_util/tuple/comparison_operators/constrained.cc:
New test.
* testsuite/20_util/variant/relops/constrained.cc: New test.
* testsuite/20_util/tuple/comparison_operators/overloaded.cc:
Disable for C++20 and later.
* testsuite/20_util/tuple/comparison_operators/overloaded2.cc:
Remove dg-error line for target c++20.
Diffstat (limited to 'gcc/expr.cc')
0 files changed, 0 insertions, 0 deletions