1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
12 // XFAIL: availability-bad_optional_access-missing && !no-exceptions
14 // constexpr T& optional<T>::value() &&;
17 #include <type_traits>
20 #include "test_macros.h"
23 using std::bad_optional_access
;
29 constexpr int test() const & {return 3;}
30 int test() & {return 4;}
31 constexpr int test() const && {return 5;}
32 int test() && {return 6;}
37 constexpr int test() && {return 7;}
44 return std::move(opt
).value().test();
50 optional
<X
> opt
; ((void)opt
);
51 ASSERT_NOT_NOEXCEPT(std::move(opt
).value());
52 ASSERT_SAME_TYPE(decltype(std::move(opt
).value()), X
&&);
57 assert(std::move(opt
).value().test() == 6);
59 #ifndef TEST_HAS_NO_EXCEPTIONS
64 (void)std::move(opt
).value();
67 catch (const bad_optional_access
&)
72 static_assert(test() == 7, "");