[Mips] Add the missing judgment when processing function handleMFLOSlot (#121463)
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.object / optional.object.observe / value_rvalue.pass.cpp
blob5de0187b495727136d73c51a9c2cfff926e4c7cf
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
10 // <optional>
12 // constexpr T& optional<T>::value() &&;
14 #include <optional>
15 #include <type_traits>
16 #include <cassert>
18 #include "test_macros.h"
20 using std::optional;
21 using std::bad_optional_access;
23 struct X
25 X() = default;
26 X(const X&) = delete;
27 constexpr int test() const & {return 3;}
28 int test() & {return 4;}
29 constexpr int test() const && {return 5;}
30 int test() && {return 6;}
33 struct Y
35 constexpr int test() && {return 7;}
38 constexpr int
39 test()
41 optional<Y> opt{Y{}};
42 return std::move(opt).value().test();
45 int main(int, char**)
48 optional<X> opt; ((void)opt);
49 ASSERT_NOT_NOEXCEPT(std::move(opt).value());
50 ASSERT_SAME_TYPE(decltype(std::move(opt).value()), X&&);
53 optional<X> opt;
54 opt.emplace();
55 assert(std::move(opt).value().test() == 6);
57 #ifndef TEST_HAS_NO_EXCEPTIONS
59 optional<X> opt;
60 try
62 (void)std::move(opt).value();
63 assert(false);
65 catch (const bad_optional_access&)
69 #endif
70 static_assert(test() == 7, "");
72 return 0;