1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11, c++14 11 12 // XFAIL: with_system_cxx_lib=macosx10.12 13 // XFAIL: with_system_cxx_lib=macosx10.11 14 // XFAIL: with_system_cxx_lib=macosx10.10 15 // XFAIL: with_system_cxx_lib=macosx10.9 16 // XFAIL: with_system_cxx_lib=macosx10.7 17 // XFAIL: with_system_cxx_lib=macosx10.8 18 19 // <optional> 20 21 // constexpr const T& optional<T>::value() const &&; 22 23 #include <optional> 24 #include <type_traits> 25 #include <cassert> 26 27 #include "test_macros.h" 28 29 using std::optional; 30 using std::in_place_t; 31 using std::in_place; 32 using std::bad_optional_access; 33 34 struct X 35 { 36 X() = default; 37 X(const X&) = delete; testX38 constexpr int test() const & {return 3;} testX39 int test() & {return 4;} testX40 constexpr int test() const && {return 5;} testX41 int test() && {return 6;} 42 }; 43 main()44int main() 45 { 46 { 47 const optional<X> opt; ((void)opt); 48 ASSERT_NOT_NOEXCEPT(std::move(opt).value()); 49 ASSERT_SAME_TYPE(decltype(std::move(opt).value()), X const&&); 50 } 51 { 52 constexpr optional<X> opt(in_place); 53 static_assert(std::move(opt).value().test() == 5, ""); 54 } 55 { 56 const optional<X> opt(in_place); 57 assert(std::move(opt).value().test() == 5); 58 } 59 #ifndef TEST_HAS_NO_EXCEPTIONS 60 { 61 const optional<X> opt; 62 try 63 { 64 (void)std::move(opt).value(); 65 assert(false); 66 } 67 catch (const bad_optional_access&) 68 { 69 } 70 } 71 #endif 72 } 73