Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.object / optional.object.observe / dereference_rvalue.pass.cpp
blob67edbb903353e210306c1af997a9e744b21d4c71
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>::operator*() &&;
14 #include <optional>
15 #include <type_traits>
16 #include <cassert>
18 #include "test_macros.h"
20 using std::optional;
22 struct X
24 constexpr int test() const& {return 3;}
25 int test() & {return 4;}
26 constexpr int test() const&& {return 5;}
27 int test() && {return 6;}
30 struct Y
32 constexpr int test() && {return 7;}
35 constexpr int
36 test()
38 optional<Y> opt{Y{}};
39 return (*std::move(opt)).test();
42 int main(int, char**)
45 optional<X> opt; ((void)opt);
46 ASSERT_SAME_TYPE(decltype(*std::move(opt)), X&&);
47 LIBCPP_STATIC_ASSERT(noexcept(*opt));
48 // ASSERT_NOT_NOEXCEPT(*std::move(opt));
49 // FIXME: This assertion fails with GCC because it can see that
50 // (A) operator*() is constexpr, and
51 // (B) there is no path through the function that throws.
52 // It's arguable if this is the correct behavior for the noexcept
53 // operator.
54 // Regardless this function should still be noexcept(false) because
55 // it has a narrow contract.
58 optional<X> opt(X{});
59 assert((*std::move(opt)).test() == 6);
61 static_assert(test() == 7, "");
63 return 0;