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, c++17, c++20
10
11// constexpr const T* operator->() const noexcept;
12// constexpr T* operator->() noexcept;
13
14#include <cassert>
15#include <concepts>
16#include <expected>
17#include <type_traits>
18#include <utility>
19
20#include "test_macros.h"
21
22// Test noexcept
23template <class T>
24concept ArrowNoexcept =
25 requires(T t) {
26 { t.operator->() } noexcept;
27 };
28
29static_assert(!ArrowNoexcept<int>);
30
31static_assert(ArrowNoexcept<std::expected<int, int>>);
32static_assert(ArrowNoexcept<const std::expected<int, int>>);
33
34constexpr bool test() {
35 // const
36 {
37 const std::expected<int, int> e(5);
38 std::same_as<const int*> decltype(auto) x = e.operator->();
39 assert(x == &(e.value()));
40 assert(*x == 5);
41 }
42
43 // non-const
44 {
45 std::expected<int, int> e(5);
46 std::same_as<int*> decltype(auto) x = e.operator->();
47 assert(x == &(e.value()));
48 assert(*x == 5);
49 }
50
51 return true;
52}
53
54int main(int, char**) {
55 test();
56 static_assert(test());
57 return 0;
58}
59

source code of libcxx/test/std/utilities/expected/expected.expected/observers/arrow.pass.cpp