xref: /llvm-project/libcxx/test/std/utilities/expected/expected.void/observers/deref.pass.cpp (revision 6a54dfbfe534276d644d7f9c027f0deeb748dd53)
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 void operator*() const & 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 DerefNoexcept =
24     requires(T t) {
25       { std::forward<T>(t).operator*() } noexcept;
26     };
27 
28 static_assert(!DerefNoexcept<int>);
29 
30 static_assert(DerefNoexcept<std::expected<void, int>>);
31 
32 constexpr bool test() {
33   const std::expected<void, int> e;
34   *e;
35   static_assert(std::is_same_v<decltype(*e), void>);
36 
37   return true;
38 }
39 
40 int main(int, char**) {
41   test();
42   static_assert(test());
43   return 0;
44 }
45