libstdc++: Fix std::bad_expected_access constructor [PR105146]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 8 Apr 2022 17:04:04 +0000 (18:04 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 8 Apr 2022 17:30:06 +0000 (18:30 +0100)
libstdc++-v3/ChangeLog:

PR libstdc++/105146
* include/std/expected (bad_expected_access): Move constructor
parameter.
* testsuite/20_util/expected/bad.cc: New test.

libstdc++-v3/include/std/expected
libstdc++-v3/testsuite/20_util/expected/bad.cc [new file with mode: 0644]

index 39d07cd..7b01a17 100644 (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;
 
diff --git a/libstdc++-v3/testsuite/20_util/expected/bad.cc b/libstdc++-v3/testsuite/20_util/expected/bad.cc
new file mode 100644 (file)
index 0000000..17bc6d6
--- /dev/null
@@ -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{});
+}