1 | //===----------------------------------------------------------------------===// |
2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
3 | // See https://llvm.org/LICENSE.txt for license information. |
4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
5 | // |
6 | //===----------------------------------------------------------------------===// |
7 | |
8 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
9 | |
10 | // constexpr const T* operator->() const noexcept; |
11 | // constexpr T* operator->() noexcept; |
12 | |
13 | #include <cassert> |
14 | #include <concepts> |
15 | #include <expected> |
16 | #include <type_traits> |
17 | #include <utility> |
18 | |
19 | #include "test_macros.h" |
20 | |
21 | // Test noexcept |
22 | template <class T> |
23 | concept ArrowNoexcept = |
24 | requires(T t) { |
25 | { t.operator->() } noexcept; |
26 | }; |
27 | |
28 | static_assert(!ArrowNoexcept<int>); |
29 | |
30 | static_assert(ArrowNoexcept<std::expected<int, int>>); |
31 | static_assert(ArrowNoexcept<const std::expected<int, int>>); |
32 | |
33 | constexpr bool test() { |
34 | // const |
35 | { |
36 | const std::expected<int, int> e(5); |
37 | std::same_as<const int*> decltype(auto) x = e.operator->(); |
38 | assert(x == &(e.value())); |
39 | assert(*x == 5); |
40 | } |
41 | |
42 | // non-const |
43 | { |
44 | std::expected<int, int> e(5); |
45 | std::same_as<int*> decltype(auto) x = e.operator->(); |
46 | assert(x == &(e.value())); |
47 | assert(*x == 5); |
48 | } |
49 | |
50 | return true; |
51 | } |
52 | |
53 | int main(int, char**) { |
54 | test(); |
55 | static_assert(test()); |
56 | return 0; |
57 | } |
58 | |