1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // result_of<Fn(ArgTypes...)>
15 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
16 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
18 #include <type_traits>
22 #include "test_macros.h"
24 // Ignore warnings about volatile in parameters being deprecated.
25 // We know it is, but we still have to test it.
26 #if defined(TEST_COMPILER_GCC)
27 # pragma GCC diagnostic ignored "-Wvolatile"
32 wat
& operator*() { return *this; }
37 struct FD
: public F
{};
40 template <typename T
, typename U
>
41 struct test_invoke_result
;
43 template <typename Fn
, typename
...Args
, typename Ret
>
44 struct test_invoke_result
<Fn(Args
...), Ret
>
48 static_assert(std::is_invocable
<Fn
, Args
...>::value
, "");
49 static_assert(std::is_invocable_r
<Ret
, Fn
, Args
...>::value
, "");
50 ASSERT_SAME_TYPE(Ret
, typename
std::invoke_result
<Fn
, Args
...>::type
);
51 ASSERT_SAME_TYPE(Ret
, std::invoke_result_t
<Fn
, Args
...>);
56 template <class T
, class U
>
57 void test_result_of_imp()
59 ASSERT_SAME_TYPE(U
, typename
std::result_of
<T
>::type
);
61 ASSERT_SAME_TYPE(U
, std::result_of_t
<T
>);
64 test_invoke_result
<T
, U
>::call();
68 // Do not warn on deprecated uses of 'volatile' below.
69 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
75 test_result_of_imp
<PMD(F
&), char &>();
76 test_result_of_imp
<PMD(F
const &), char const &>();
77 test_result_of_imp
<PMD(F
volatile &), char volatile &>();
78 test_result_of_imp
<PMD(F
const volatile &), char const volatile &>();
80 test_result_of_imp
<PMD(F
&&), char &&>();
81 test_result_of_imp
<PMD(F
const &&), char const &&>();
82 test_result_of_imp
<PMD(F
volatile &&), char volatile &&>();
83 test_result_of_imp
<PMD(F
const volatile &&), char const volatile &&>();
85 test_result_of_imp
<PMD(F
), char &&>();
86 test_result_of_imp
<PMD(F
const ), char &&>();
87 test_result_of_imp
<PMD(F
volatile ), char &&>();
88 test_result_of_imp
<PMD(F
const volatile ), char &&>();
90 test_result_of_imp
<PMD(FD
&), char &>();
91 test_result_of_imp
<PMD(FD
const &), char const &>();
92 test_result_of_imp
<PMD(FD
volatile &), char volatile &>();
93 test_result_of_imp
<PMD(FD
const volatile &), char const volatile &>();
95 test_result_of_imp
<PMD(FD
&&), char &&>();
96 test_result_of_imp
<PMD(FD
const &&), char const &&>();
97 test_result_of_imp
<PMD(FD
volatile &&), char volatile &&>();
98 test_result_of_imp
<PMD(FD
const volatile &&), char const volatile &&>();
100 test_result_of_imp
<PMD(FD
), char &&>();
101 test_result_of_imp
<PMD(FD
const ), char &&>();
102 test_result_of_imp
<PMD(FD
volatile ), char &&>();
103 test_result_of_imp
<PMD(FD
const volatile ), char &&>();
105 test_result_of_imp
<PMD(std::unique_ptr
<F
>), char &>();
106 test_result_of_imp
<PMD(std::unique_ptr
<F
const>), const char &>();
107 test_result_of_imp
<PMD(std::unique_ptr
<FD
>), char &>();
108 test_result_of_imp
<PMD(std::unique_ptr
<FD
const>), const char &>();
110 test_result_of_imp
<PMD(std::reference_wrapper
<F
>), char &>();
111 test_result_of_imp
<PMD(std::reference_wrapper
<F
const>), const char &>();
112 test_result_of_imp
<PMD(std::reference_wrapper
<FD
>), char &>();
113 test_result_of_imp
<PMD(std::reference_wrapper
<FD
const>), const char &>();
116 test_result_of_imp
<int (F::* (F
&)) () &, int> ();
117 test_result_of_imp
<int (F::* (F
&)) () const &, int> ();
118 test_result_of_imp
<int (F::* (F
&)) () volatile &, int> ();
119 test_result_of_imp
<int (F::* (F
&)) () const volatile &, int> ();
120 test_result_of_imp
<int (F::* (F
const &)) () const &, int> ();
121 test_result_of_imp
<int (F::* (F
const &)) () const volatile &, int> ();
122 test_result_of_imp
<int (F::* (F
volatile &)) () volatile &, int> ();
123 test_result_of_imp
<int (F::* (F
volatile &)) () const volatile &, int> ();
124 test_result_of_imp
<int (F::* (F
const volatile &)) () const volatile &, int> ();
126 test_result_of_imp
<int (F::* (F
&&)) () &&, int> ();
127 test_result_of_imp
<int (F::* (F
&&)) () const &&, int> ();
128 test_result_of_imp
<int (F::* (F
&&)) () volatile &&, int> ();
129 test_result_of_imp
<int (F::* (F
&&)) () const volatile &&, int> ();
130 test_result_of_imp
<int (F::* (F
const &&)) () const &&, int> ();
131 test_result_of_imp
<int (F::* (F
const &&)) () const volatile &&, int> ();
132 test_result_of_imp
<int (F::* (F
volatile &&)) () volatile &&, int> ();
133 test_result_of_imp
<int (F::* (F
volatile &&)) () const volatile &&, int> ();
134 test_result_of_imp
<int (F::* (F
const volatile &&)) () const volatile &&, int> ();
136 test_result_of_imp
<int (F::* (F
)) () &&, int> ();
137 test_result_of_imp
<int (F::* (F
)) () const &&, int> ();
138 test_result_of_imp
<int (F::* (F
)) () volatile &&, int> ();
139 test_result_of_imp
<int (F::* (F
)) () const volatile &&, int> ();
140 test_result_of_imp
<int (F::* (F
const )) () const &&, int> ();
141 test_result_of_imp
<int (F::* (F
const )) () const volatile &&, int> ();
142 test_result_of_imp
<int (F::* (F
volatile )) () volatile &&, int> ();
143 test_result_of_imp
<int (F::* (F
volatile )) () const volatile &&, int> ();
144 test_result_of_imp
<int (F::* (F
const volatile )) () const volatile &&, int> ();
147 test_result_of_imp
<int (F::* (FD
&)) () &, int> ();
148 test_result_of_imp
<int (F::* (FD
&)) () const &, int> ();
149 test_result_of_imp
<int (F::* (FD
&)) () volatile &, int> ();
150 test_result_of_imp
<int (F::* (FD
&)) () const volatile &, int> ();
151 test_result_of_imp
<int (F::* (FD
const &)) () const &, int> ();
152 test_result_of_imp
<int (F::* (FD
const &)) () const volatile &, int> ();
153 test_result_of_imp
<int (F::* (FD
volatile &)) () volatile &, int> ();
154 test_result_of_imp
<int (F::* (FD
volatile &)) () const volatile &, int> ();
155 test_result_of_imp
<int (F::* (FD
const volatile &)) () const volatile &, int> ();
157 test_result_of_imp
<int (F::* (FD
&&)) () &&, int> ();
158 test_result_of_imp
<int (F::* (FD
&&)) () const &&, int> ();
159 test_result_of_imp
<int (F::* (FD
&&)) () volatile &&, int> ();
160 test_result_of_imp
<int (F::* (FD
&&)) () const volatile &&, int> ();
161 test_result_of_imp
<int (F::* (FD
const &&)) () const &&, int> ();
162 test_result_of_imp
<int (F::* (FD
const &&)) () const volatile &&, int> ();
163 test_result_of_imp
<int (F::* (FD
volatile &&)) () volatile &&, int> ();
164 test_result_of_imp
<int (F::* (FD
volatile &&)) () const volatile &&, int> ();
165 test_result_of_imp
<int (F::* (FD
const volatile &&)) () const volatile &&, int> ();
167 test_result_of_imp
<int (F::* (FD
)) () &&, int> ();
168 test_result_of_imp
<int (F::* (FD
)) () const &&, int> ();
169 test_result_of_imp
<int (F::* (FD
)) () volatile &&, int> ();
170 test_result_of_imp
<int (F::* (FD
)) () const volatile &&, int> ();
171 test_result_of_imp
<int (F::* (FD
const )) () const &&, int> ();
172 test_result_of_imp
<int (F::* (FD
const )) () const volatile &&, int> ();
173 test_result_of_imp
<int (F::* (FD
volatile )) () volatile &&, int> ();
174 test_result_of_imp
<int (F::* (FD
volatile )) () const volatile &&, int> ();
175 test_result_of_imp
<int (F::* (FD
const volatile )) () const volatile &&, int> ();
178 test_result_of_imp
<int (F::* (std::reference_wrapper
<F
>)) (), int>();
179 test_result_of_imp
<int (F::* (std::reference_wrapper
<const F
>)) () const, int>();
180 test_result_of_imp
<int (F::* (std::unique_ptr
<F
> )) (), int>();
181 test_result_of_imp
<int (F::* (std::unique_ptr
<const F
> )) () const, int>();
183 test_result_of_imp
<decltype(&wat::foo
)(wat
), void>();
188 _LIBCPP_SUPPRESS_DEPRECATED_POP