Debian Codegraph @

libcxx/test/std/utilities/optional/optional.object/optional.object.observe/op_arrow_const.pass.cpp

raw
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 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03, c++11, c++14
10 // <optional>
11
12 // constexpr const T* optional<T>::operator->() const;
13
14 #include <optional>
15 #include <type_traits>
16 #include <cassert>
17
18 #include "test_macros.h"
19
20 using std::optional;
21
22 struct X
23 {
24 constexpr int test() const {return 3;}
25 };
26
27 struct Y
28 {
29 int test() const noexcept {return 2;}
30 };
31
32 struct Z
33 {
34 const Z* operator&() const;
35 constexpr int test() const {return 1;}
36 };
37
38 int main(int, char**)
39 {
40 {
41 const std::optional<X> opt; ((void)opt);
42 ASSERT_SAME_TYPE(decltype(opt.operator->()), X const*);
43 ASSERT_NOEXCEPT(opt.operator->());
44 }
45 {
46 constexpr optional<X> opt(X{});
47 static_assert(opt->test() == 3, "");
48 }
49 {
50 constexpr optional<Y> opt(Y{});
51 assert(opt->test() == 2);
52 }
53 {
54 constexpr optional<Z> opt(Z{});
55 static_assert(opt->test() == 1, "");
56 }
57
58 return 0;
59 }