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 10 11 // Throwing bad_optional_access is supported starting in macosx10.13 12 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12 && !no-exceptions 13 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11 && !no-exceptions 14 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10 && !no-exceptions 15 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9 && !no-exceptions 16 17 // <optional> 18 // 19 // template <class T> 20 // constexpr optional<decay_t<T>> make_optional(T&& v); 21 22 #include <optional> 23 #include <string> 24 #include <memory> 25 #include <cassert> 26 27 #include "test_macros.h" 28 29 int main(int, char**) 30 { 31 using std::optional; 32 using std::make_optional; 33 { 34 int arr[10]; ((void)arr); 35 ASSERT_SAME_TYPE(decltype(make_optional(arr)), optional<int*>); 36 } 37 { 38 constexpr auto opt = make_optional(2); 39 ASSERT_SAME_TYPE(decltype(opt), const optional<int>); 40 static_assert(opt.value() == 2); 41 } 42 { 43 optional<int> opt = make_optional(2); 44 assert(*opt == 2); 45 } 46 { 47 std::string s("123"); 48 optional<std::string> opt = make_optional(s); 49 assert(*opt == s); 50 } 51 { 52 std::unique_ptr<int> s(new int(3)); 53 optional<std::unique_ptr<int>> opt = make_optional(std::move(s)); 54 assert(**opt == 3); 55 assert(s == nullptr); 56 } 57 58 return 0; 59 } 60