summaryrefslogtreecommitdiff
path: root/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp')
-rw-r--r--libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp
new file mode 100644
index 000000000000..a36665b25c87
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// Test the mandates
+// template<class G = E> constexpr E error_or(G&&) const &;
+// Mandates: is_copy_constructible_v<G> is true and is_convertible_v<U, E> is true.
+
+// template<class G = E> constexpr E error_or(G&&) &&;
+// Mandates: is_move_constructible_v<G> is true and is_convertible_v<U, E> is true.
+
+#include <expected>
+#include <utility>
+
+struct NonCopyable {
+ NonCopyable(int) {}
+ NonCopyable(const NonCopyable&) = delete;
+};
+
+struct NonMovable {
+ NonMovable(int) {}
+ NonMovable(NonMovable&&) = delete;
+};
+
+struct NotConvertibleFromInt {};
+
+// clang-format off
+void test() {
+ // const & overload
+ // !is_copy_constructible_v<G>,
+ {
+ const std::expected<void, NonCopyable> f1(std::unexpect, 0);
+ f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NonCopyable>::error_or<int>' requested here}}
+ // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed {{.*}}error_type has to be copy constructible}}
+ // expected-error-re@*:* {{call to deleted constructor of{{.*}}}}
+ }
+
+ // const & overload
+ // !is_convertible_v<U, T>
+ {
+ const std::expected<void, NotConvertibleFromInt> f1(std::unexpect, NotConvertibleFromInt{});
+ f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NotConvertibleFromInt>::error_or<int>' requested here}}
+ // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed {{.*}}argument has to be convertible to error_type}}
+ // expected-error-re@*:* {{no viable conversion from returned value of type{{.*}}}}
+ }
+
+ // && overload
+ // !is_move_constructible_v<T>,
+ {
+ std::expected<void, NonMovable> f1(std::unexpect, 0);
+ std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NonMovable>::error_or<int>' requested here}}
+ // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed {{.*}}error_type has to be move constructible}}
+ // expected-error-re@*:* {{call to deleted constructor of{{.*}}}}
+ }
+
+ // && overload
+ // !is_convertible_v<U, T>
+ {
+ std::expected<void, NotConvertibleFromInt> f1(std::unexpect, NotConvertibleFromInt{});
+ std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NotConvertibleFromInt>::error_or<int>' requested here}}
+ // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed {{.*}}argument has to be convertible to error_type}}
+ // expected-error-re@*:* {{no viable conversion from returned value of type{{.*}}}}
+ }
+}
+// clang-format on