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