//===----------------------------------------------------------------------===// // // 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 // // template // constexpr optional make_optional(Args&&... args); // GCC crashes on this file, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120577 // XFAIL: gcc-15 #include #include #include #include #include #include "test_macros.h" template constexpr bool test_ref() { T i{0}; auto opt = std::make_optional(i); #if TEST_STD_VER < 26 assert((std::is_same_v>)); #else assert((std::is_same_v>)); #endif assert(*opt == 0); return true; } int main(int, char**) { { constexpr auto opt = std::make_optional('a'); static_assert(*opt == int('a')); } { std::string s = "123"; auto opt = std::make_optional(s); assert(*opt == "123"); } { std::unique_ptr s = std::make_unique(3); auto opt = std::make_optional>(std::move(s)); assert(**opt == 3); assert(s == nullptr); } { auto opt = std::make_optional(4u, 'X'); assert(*opt == "XXXX"); } using namespace std::string_view_literals; static_assert(test_ref()); assert((test_ref())); static_assert(test_ref()); assert((test_ref())); return 0; }