Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / optional / optional.object / optional.object.observe / op_arrow_const.pass.cpp
blobb9c1fe7794b665e58069fd5ea669c7b4689f034e
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 const 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;}
27 struct Y
29 int test() const noexcept {return 2;}
32 struct Z
34 const Z* operator&() const;
35 constexpr int test() const {return 1;}
38 int main(int, char**)
41 const std::optional<X> opt; ((void)opt);
42 ASSERT_SAME_TYPE(decltype(opt.operator->()), X const*);
43 // ASSERT_NOT_NOEXCEPT(opt.operator->());
44 // FIXME: This assertion fails with GCC because it can see that
45 // (A) operator->() is constexpr, and
46 // (B) there is no path through the function that throws.
47 // It's arguable if this is the correct behavior for the noexcept
48 // operator.
49 // Regardless this function should still be noexcept(false) because
50 // it has a narrow contract.
53 constexpr optional<X> opt(X{});
54 static_assert(opt->test() == 3, "");
57 constexpr optional<Y> opt(Y{});
58 assert(opt->test() == 2);
61 constexpr optional<Z> opt(Z{});
62 static_assert(opt->test() == 1, "");
65 return 0;