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 // constexpr T& optional<T>::value() &&;
15 #include <type_traits>
18 #include "test_macros.h"
21 using std::bad_optional_access
;
27 constexpr int test() const & {return 3;}
28 int test() & {return 4;}
29 constexpr int test() const && {return 5;}
30 int test() && {return 6;}
35 constexpr int test() && {return 7;}
42 return std::move(opt
).value().test();
48 optional
<X
> opt
; ((void)opt
);
49 ASSERT_NOT_NOEXCEPT(std::move(opt
).value());
50 ASSERT_SAME_TYPE(decltype(std::move(opt
).value()), X
&&);
55 assert(std::move(opt
).value().test() == 6);
57 #ifndef TEST_HAS_NO_EXCEPTIONS
62 (void)std::move(opt
).value();
65 catch (const bad_optional_access
&)
70 static_assert(test() == 7, "");