//===----------------------------------------------------------------------===// // // 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 // // constexpr expected(); // Constraints: is_default_constructible_v is true. // // Effects: Value-initializes val. // Postconditions: has_value() is true. // // Throws: Any exception thrown by the initialization of val. #include #include #include #include "test_macros.h" #include "../../types.h" struct NoDedefaultCtor { NoDedefaultCtor() = delete; }; // Test constraints static_assert(std::is_default_constructible_v>); static_assert(!std::is_default_constructible_v>); struct MyInt { int i; friend constexpr bool operator==(const MyInt&, const MyInt&) = default; }; template constexpr void testDefaultCtor() { std::expected e; assert(e.has_value()); assert(e.value() == T()); } template constexpr void testTypes() { testDefaultCtor(); testDefaultCtor(); testDefaultCtor(); } constexpr bool test() { testTypes(); testTypes(); testTypes>(); return true; } void testException() { #ifndef TEST_HAS_NO_EXCEPTIONS struct Throwing { Throwing() { throw Except{}; }; }; try { std::expected u; assert(false); } catch (Except) { } #endif // TEST_HAS_NO_EXCEPTIONS } int main(int, char**) { test(); static_assert(test()); testException(); return 0; }