| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | |
| 11 | // constexpr expected() noexcept; |
| 12 | |
| 13 | #include <cassert> |
| 14 | #include <expected> |
| 15 | #include <type_traits> |
| 16 | |
| 17 | #include "test_macros.h" |
| 18 | |
| 19 | // Test noexcept |
| 20 | |
| 21 | struct NoDefaultCtor { |
| 22 | constexpr NoDefaultCtor() = delete; |
| 23 | }; |
| 24 | |
| 25 | static_assert(std::is_nothrow_default_constructible_v<std::expected<void, int>>); |
| 26 | static_assert(std::is_nothrow_default_constructible_v<std::expected<void, NoDefaultCtor>>); |
| 27 | |
| 28 | struct MyInt { |
| 29 | int i; |
| 30 | friend constexpr bool operator==(const MyInt&, const MyInt&) = default; |
| 31 | }; |
| 32 | |
| 33 | constexpr bool test() { |
| 34 | // default constructible |
| 35 | { |
| 36 | std::expected<void, int> e; |
| 37 | assert(e.has_value()); |
| 38 | } |
| 39 | |
| 40 | // non-default constructible |
| 41 | { |
| 42 | std::expected<void, NoDefaultCtor> e; |
| 43 | assert(e.has_value()); |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | int main(int, char**) { |
| 50 | test(); |
| 51 | static_assert(test()); |
| 52 | return 0; |
| 53 | } |
| 54 | |