[memprof] Move YAML traits to MemProf.h (NFC) (#118668)
[llvm-project.git] / libcxx / test / std / utilities / expected / expected.bad / error.member.pass.cpp
blob01f666274cbee3e78403b07cf7ff17bb3a931d8b
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // E& error() & noexcept;
12 // const E& error() const & noexcept;
13 // E&& error() && noexcept;
14 // const E&& error() const && noexcept;
16 #include <cassert>
17 #include <concepts>
18 #include <expected>
19 #include <utility>
21 template <class T>
22 concept ErrorNoexcept =
23 requires(T&& t) {
24 { std::forward<T>(t).error() } noexcept;
27 static_assert(!ErrorNoexcept<int>);
28 static_assert(ErrorNoexcept<std::bad_expected_access<int>&>);
29 static_assert(ErrorNoexcept<std::bad_expected_access<int> const&>);
30 static_assert(ErrorNoexcept<std::bad_expected_access<int>&&>);
31 static_assert(ErrorNoexcept<std::bad_expected_access<int> const&&>);
33 void test() {
34 // &
36 std::bad_expected_access<int> e(5);
37 decltype(auto) i = e.error();
38 static_assert(std::same_as<decltype(i), int&>);
39 assert(i == 5);
42 // const &
44 const std::bad_expected_access<int> e(5);
45 decltype(auto) i = e.error();
46 static_assert(std::same_as<decltype(i), const int&>);
47 assert(i == 5);
50 // &&
52 std::bad_expected_access<int> e(5);
53 decltype(auto) i = std::move(e).error();
54 static_assert(std::same_as<decltype(i), int&&>);
55 assert(i == 5);
58 // const &&
60 const std::bad_expected_access<int> e(5);
61 decltype(auto) i = std::move(e).error();
62 static_assert(std::same_as<decltype(i), const int&&>);
63 assert(i == 5);
67 int main(int, char**) {
68 test();
69 return 0;