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
10 
11 // <coroutine>
12 
13 // template <class Promise = void>
14 // struct coroutine_handle;
15 
16 // namespace std {
17 //  template <class P> struct hash<coroutine_handle<P>>;
18 // }
19 
20 #include <coroutine>
21 #include <type_traits>
22 #include <memory>
23 #include <utility>
24 #include <cstdint>
25 #include <cassert>
26 #include <functional>
27 
28 #include "test_macros.h"
29 
30 template <class C>
do_test(int * LHSVal,int * RHSVal)31 void do_test(int *LHSVal, int *RHSVal) {
32   [[maybe_unused]] const std::size_t ExpectLHS = std::hash<void*>{}(LHSVal);
33   [[maybe_unused]] const std::size_t ExpectRHS = std::hash<void*>{}(RHSVal);
34   const C LHS = C::from_address(LHSVal);
35   const C RHS = C::from_address(RHSVal);
36   const std::hash<C> h;
37 
38   LIBCPP_ASSERT(h(LHS) == ExpectLHS);
39   LIBCPP_ASSERT(h(RHS) == ExpectRHS);
40   assert((h(LHS) == h(RHS)) == (LHSVal == RHSVal));
41   {
42     ASSERT_SAME_TYPE(decltype(h(LHS)), std::size_t);
43     ASSERT_NOEXCEPT(std::hash<C>{}(LHS));
44   }
45 }
46 
main(int,char **)47 int main(int, char**)
48 {
49   int i, j;
50   std::pair<int *, int *> const TestCases[] = {
51       {nullptr, nullptr},
52       {nullptr, &i},
53       {&i, &i},
54       {&i, &j}
55   };
56   for (auto& TC : TestCases) {
57     do_test<std::coroutine_handle<>>(TC.first, TC.second);
58     do_test<std::coroutine_handle<int>>(TC.first, TC.second);
59   }
60 
61   return 0;
62 }
63