[libcxx-commits] [libcxx] [libc++] Implement LWG3940 (std::expected<void, E>::value() also needs E to be copy constructible) (PR #71819)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 15 09:34:57 PST 2023


================
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// ADDITIONAL_COMPILE_FLAGS: -Xclang -verify-ignore-unexpected=error
+
+// constexpr void value() &&;
+// Mandates: is_copy_constructible_v<E> is true and is_move_constructible_v<E> is true.
+
+#include <expected>
+
+#include "MoveOnly.h"
+
+void test() {
+  // MoveOnly type as error_type
+  std::expected<void, MoveOnly> e(std::unexpect, 5);
+
+  std::move(e)
+      .value(); // expected-note{{in instantiation of member function 'std::expected<void, MoveOnly>::value' requested here}}
+  // expected-error-re@*:* {{static assertion failed due to requirement 'is_copy_constructible_v<MoveOnly>': error_type has to be both copy constructible and move constructible}}
+}
+
+int main(int, char**) { test(); }
----------------
huixie90 wrote:

we don't need this line. the verify test is not meant to be run

https://github.com/llvm/llvm-project/pull/71819


More information about the libcxx-commits mailing list