1 | //===----------------------------------------------------------------------===// |
2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
3 | // See https://llvm.org/LICENSE.txt for license information. |
4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
5 | // |
6 | //===----------------------------------------------------------------------===// |
7 | |
8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
9 | |
10 | // constexpr expected() noexcept; |
11 | |
12 | #include <cassert> |
13 | #include <expected> |
14 | #include <type_traits> |
15 | |
16 | #include "test_macros.h" |
17 | |
18 | // Test noexcept |
19 | |
20 | struct NoDefaultCtor { |
21 | constexpr NoDefaultCtor() = delete; |
22 | }; |
23 | |
24 | static_assert(std::is_nothrow_default_constructible_v<std::expected<void, int>>); |
25 | static_assert(std::is_nothrow_default_constructible_v<std::expected<void, NoDefaultCtor>>); |
26 | |
27 | struct MyInt { |
28 | int i; |
29 | friend constexpr bool operator==(const MyInt&, const MyInt&) = default; |
30 | }; |
31 | |
32 | constexpr bool test() { |
33 | // default constructible |
34 | { |
35 | std::expected<void, int> e; |
36 | assert(e.has_value()); |
37 | } |
38 | |
39 | // non-default constructible |
40 | { |
41 | std::expected<void, NoDefaultCtor> e; |
42 | assert(e.has_value()); |
43 | } |
44 | |
45 | return true; |
46 | } |
47 | |
48 | int main(int, char**) { |
49 | test(); |
50 | static_assert(test()); |
51 | return 0; |
52 | } |
53 | |