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_const_rvalue.pass.cpp
blob68591c5e2dbcb8090c716bc890e48613d451f547
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*() const &&;
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 int test() const && {return 2;}
35 int main(int, char**)
38 const optional<X> opt; ((void)opt);
39 ASSERT_SAME_TYPE(decltype(*std::move(opt)), X const &&);
40 LIBCPP_STATIC_ASSERT(noexcept(*opt));
41 // ASSERT_NOT_NOEXCEPT(*std::move(opt));
42 // FIXME: This assertion fails with GCC because it can see that
43 // (A) operator*() is constexpr, and
44 // (B) there is no path through the function that throws.
45 // It's arguable if this is the correct behavior for the noexcept
46 // operator.
47 // Regardless this function should still be noexcept(false) because
48 // it has a narrow contract.
51 constexpr optional<X> opt(X{});
52 static_assert((*std::move(opt)).test() == 5, "");
55 constexpr optional<Y> opt(Y{});
56 assert((*std::move(opt)).test() == 2);
59 return 0;