libstdc++: Fix std::bad_expected_access constructor [PR105146]

libstdc++-v3/ChangeLog:

	PR libstdc++/105146
	* include/std/expected (bad_expected_access): Move constructor
	parameter.
	* testsuite/20_util/expected/bad.cc: New test.
This commit is contained in:
Jonathan Wakely 2022-04-08 18:04:04 +01:00
parent 5522dec054
commit 29e355d0d6
2 changed files with 16 additions and 1 deletions

View file

@ -95,7 +95,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class bad_expected_access : public bad_expected_access<void> {
public:
explicit
bad_expected_access(_Er __e) : _M_val(__e) { }
bad_expected_access(_Er __e) : _M_val(std::move(__e)) { }
// XXX const char* what() const noexcept override;

View file

@ -0,0 +1,15 @@
// { dg-options "-std=gnu++23" }
// { dg-do compile }
#include <expected>
struct E {
E() = default;
E(E&&) = default;
};
void
test_pr105146()
{
std::bad_expected_access(E{});
}