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
11 // XFAIL: availability-bad_optional_access-missing && !no-exceptions
15 // constexpr T& optional<T>::value() &;
18 #include <type_traits>
21 #include "test_macros.h"
24 using std::bad_optional_access
;
30 constexpr int test() const & {return 3;}
31 int test() & {return 4;}
32 constexpr int test() const && {return 5;}
33 int test() && {return 6;}
38 constexpr int test() & {return 7;}
45 return opt
.value().test();
52 optional
<X
> opt
; ((void)opt
);
53 ASSERT_NOT_NOEXCEPT(opt
.value());
54 ASSERT_SAME_TYPE(decltype(opt
.value()), X
&);
59 assert(opt
.value().test() == 4);
61 #ifndef TEST_HAS_NO_EXCEPTIONS
69 catch (const bad_optional_access
&)
74 static_assert(test() == 7, "");