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 T* optional<T>::operator->();
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     int test() noexcept {return 3;}
25 };
26 
27 struct Y
28 {
29     constexpr int test() {return 3;}
30 };
31 
32 constexpr int
33 test()
34 {
35     optional<Y> opt{Y{}};
36     return opt->test();
37 }
38 
39 int main(int, char**)
40 {
41     {
42         std::optional<X> opt; ((void)opt);
43         ASSERT_SAME_TYPE(decltype(opt.operator->()), X*);
44         ASSERT_NOEXCEPT(opt.operator->());
45     }
46     {
47         optional<X> opt(X{});
48         assert(opt->test() == 3);
49     }
50     {
51         static_assert(test() == 3, "");
52     }
53 
54     return 0;
55 }
56