]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fixes for std::expected
authorJonathan Wakely <jwakely@redhat.com>
Fri, 16 Dec 2022 16:07:29 +0000 (16:07 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 21 Dec 2022 11:34:19 +0000 (11:34 +0000)
commit35ad6ec3bb6ea6ef369c2d851b52e156420046a4
tree936e8bae2a8bf4e572191247dd4dd4240d494869
parented3e8a988e0ec5b926093e26dfeef1d8b7504d1f
libstdc++: Fixes for std::expected

This fixes some bugs in the swap functions for std::expected.

It also disables the noexcept-specifiers for equality operators, because
those are problematic when querying whether a std::expected is equality
comparable. The operator==(const expected<T,E>&, const U&) function is
not constrained, so is viable for comparing expected<T,E> with
expected<void,G>, but then we get an error from the noexcept-specifier.

libstdc++-v3/ChangeLog:

* include/std/expected (expected::_M_swap_val_unex): Guard the
correct object.
(expected::swap): Move is_swappable
requirement from static_assert to constraint.
(swap): Likewise.
(operator==): Remove noexcept-specifier.
* testsuite/20_util/expected/swap.cc: Check swapping of
types without non-throwing move constructor. Check constraints
on swap.
* testsuite/20_util/expected/unexpected.cc: Check constraints on
swap.
* testsuite/20_util/expected/equality.cc: New test.

(cherry picked from commit 59822c39207c9e8be576e9d6c3370bd85ddaf886)
libstdc++-v3/include/std/expected
libstdc++-v3/testsuite/20_util/expected/equality.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/expected/swap.cc
libstdc++-v3/testsuite/20_util/expected/unexpected.cc