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: availability=macosx10.13 13 // XFAIL: availability=macosx10.12 14 // XFAIL: availability=macosx10.11 15 // XFAIL: availability=macosx10.10 16 // XFAIL: availability=macosx10.9 17 // XFAIL: availability=macosx10.8 18 // XFAIL: availability=macosx10.7 19 20 // <optional> 21 22 // constexpr const T& optional<T>::value() const &&; 23 24 #include <optional> 25 #include <type_traits> 26 #include <cassert> 27 28 #include "test_macros.h" 29 30 using std::optional; 31 using std::in_place_t; 32 using std::in_place; 33 using std::bad_optional_access; 34 35 struct X 36 { 37 X() = default; 38 X(const X&) = delete; testX39 constexpr int test() const & {return 3;} testX40 int test() & {return 4;} testX41 constexpr int test() const && {return 5;} testX42 int test() && {return 6;} 43 }; 44 main()45int main() 46 { 47 { 48 const optional<X> opt; ((void)opt); 49 ASSERT_NOT_NOEXCEPT(std::move(opt).value()); 50 ASSERT_SAME_TYPE(decltype(std::move(opt).value()), X const&&); 51 } 52 { 53 constexpr optional<X> opt(in_place); 54 static_assert(std::move(opt).value().test() == 5, ""); 55 } 56 { 57 const optional<X> opt(in_place); 58 assert(std::move(opt).value().test() == 5); 59 } 60 #ifndef TEST_HAS_NO_EXCEPTIONS 61 { 62 const optional<X> opt; 63 try 64 { 65 (void)std::move(opt).value(); 66 assert(false); 67 } 68 catch (const bad_optional_access&) 69 { 70 } 71 } 72 #endif 73 } 74