any_invocable_test.cc
Go to the documentation of this file.
1 // Copyright 2022 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <cstddef>
18 #include <initializer_list>
19 #include <numeric>
20 #include <type_traits>
21 
22 #include "gtest/gtest.h"
23 #include "absl/base/config.h"
24 #include "absl/meta/type_traits.h"
25 #include "absl/utility/utility.h"
26 
27 static_assert(absl::internal_any_invocable::kStorageSize >= sizeof(void*),
28  "These tests assume that the small object storage is at least "
29  "the size of a pointer.");
30 
31 namespace {
32 
33 // Helper macro used to avoid spelling `noexcept` in language versions older
34 // than C++17, where it is not part of the type system, in order to avoid
35 // compilation failures and internal compiler errors.
36 #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
37 #define ABSL_INTERNAL_NOEXCEPT_SPEC(noex) noexcept(noex)
38 #else
39 #define ABSL_INTERNAL_NOEXCEPT_SPEC(noex)
40 #endif
41 
42 // A dummy type we use when passing qualifiers to metafunctions
43 struct _ {};
44 
45 template <class T>
46 struct Wrapper {
47  template <class U,
49  Wrapper(U&&); // NOLINT
50 };
51 
52 // This will cause a recursive trait instantiation if the SFINAE checks are
53 // not ordered correctly for constructibility.
54 static_assert(std::is_constructible<Wrapper<absl::AnyInvocable<void()>>,
55  Wrapper<absl::AnyInvocable<void()>>>::value,
56  "");
57 
58 // A metafunction that takes the cv and l-value reference qualifiers that were
59 // associated with a function type (here passed via qualifiers of an object
60 // type), and .
61 template <class Qualifiers, class This>
62 struct QualifiersForThisImpl {
63  static_assert(std::is_object<This>::value, "");
64  using type =
66 };
67 
68 template <class Qualifiers, class This>
69 struct QualifiersForThisImpl<Qualifiers&, This>
70  : QualifiersForThisImpl<Qualifiers, This> {};
71 
72 template <class Qualifiers, class This>
73 struct QualifiersForThisImpl<Qualifiers&&, This> {
74  static_assert(std::is_object<This>::value, "");
75  using type =
77 };
78 
79 template <class Qualifiers, class This>
80 using QualifiersForThis =
81  typename QualifiersForThisImpl<Qualifiers, This>::type;
82 
83 // A metafunction that takes the cv and l-value reference qualifier of T and
84 // applies them to U's function type qualifiers.
85 template <class T, class Fun>
86 struct GiveQualifiersToFunImpl;
87 
88 template <class T, class R, class... P>
89 struct GiveQualifiersToFunImpl<T, R(P...)> {
90  using type =
92 };
93 
94 template <class T, class R, class... P>
95 struct GiveQualifiersToFunImpl<T&, R(P...)> {
96  using type =
98 };
99 
100 template <class T, class R, class... P>
101 struct GiveQualifiersToFunImpl<T&&, R(P...)> {
102  using type =
104 };
105 
106 // If noexcept is a part of the type system, then provide the noexcept forms.
107 #if defined(__cpp_noexcept_function_type)
108 
109 template <class T, class R, class... P>
110 struct GiveQualifiersToFunImpl<T, R(P...) noexcept> {
112  R(P...) const noexcept, R(P...) noexcept>;
113 };
114 
115 template <class T, class R, class... P>
116 struct GiveQualifiersToFunImpl<T&, R(P...) noexcept> {
117  using type =
119  R(P...) & noexcept>;
120 };
121 
122 template <class T, class R, class... P>
123 struct GiveQualifiersToFunImpl<T&&, R(P...) noexcept> {
124  using type =
126  R(P...) && noexcept>;
127 };
128 
129 #endif // defined(__cpp_noexcept_function_type)
130 
131 template <class T, class Fun>
132 using GiveQualifiersToFun = typename GiveQualifiersToFunImpl<T, Fun>::type;
133 
134 // This is used in template parameters to decide whether or not to use a type
135 // that fits in the small object optimization storage.
136 enum class ObjSize { small, large };
137 
138 // A base type that is used with classes as a means to insert an
139 // appropriately-sized dummy datamember when Size is ObjSize::large so that the
140 // user's class type is guaranteed to not fit in small object storage.
141 template <ObjSize Size>
142 struct TypeErasedPadding;
143 
144 template <>
145 struct TypeErasedPadding<ObjSize::small> {};
146 
147 template <>
148 struct TypeErasedPadding<ObjSize::large> {
149  char dummy_data[absl::internal_any_invocable::kStorageSize + 1] = {};
150 };
151 
152 struct Int {
153  Int(int v) noexcept : value(v) {} // NOLINT
154 #ifndef _MSC_VER
155  Int(Int&&) noexcept {
156  // NOTE: Prior to C++17, this not being called requires optimizations to
157  // take place when performing the top-level invocation. In practice,
158  // most supported compilers perform this optimization prior to C++17.
159  std::abort();
160  }
161 #else
162  Int(Int&& v) noexcept = default;
163 #endif
164  operator int() && noexcept { return value; } // NOLINT
165 
166  int MemberFunctionAdd(int const& b, int c) noexcept { // NOLINT
167  return value + b + c;
168  }
169 
170  int value;
171 };
172 
173 enum class Movable { no, yes, nothrow, trivial };
174 
175 enum class NothrowCall { no, yes };
176 
177 enum class Destructible { nothrow, trivial };
178 
179 enum class ObjAlign : std::size_t {
182 };
183 
184 // A function-object template that has knobs for each property that can affect
185 // how the object is stored in AnyInvocable.
186 template <Movable Movability, Destructible Destructibility, class Qual,
187  NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
188 struct add;
189 
190 #define ABSL_INTERNALS_ADD(qual) \
191  template <NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment> \
192  struct alignas(static_cast<std::size_t>(Alignment)) \
193  add<Movable::trivial, Destructible::trivial, _ qual, CallExceptionSpec, \
194  Size, Alignment> : TypeErasedPadding<Size> { \
195  explicit add(int state_init) : state(state_init) {} \
196  explicit add(std::initializer_list<int> state_init, int tail) \
197  : state(std::accumulate(std::begin(state_init), std::end(state_init), \
198  0) + \
199  tail) {} \
200  add(add&& other) = default; /*NOLINT*/ \
201  Int operator()(int a, int b, int c) qual \
202  ABSL_INTERNAL_NOEXCEPT_SPEC(CallExceptionSpec == NothrowCall::yes) { \
203  return state + a + b + c; \
204  } \
205  int state; \
206  }; \
207  \
208  template <NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment> \
209  struct alignas(static_cast<std::size_t>(Alignment)) \
210  add<Movable::trivial, Destructible::nothrow, _ qual, CallExceptionSpec, \
211  Size, Alignment> : TypeErasedPadding<Size> { \
212  explicit add(int state_init) : state(state_init) {} \
213  explicit add(std::initializer_list<int> state_init, int tail) \
214  : state(std::accumulate(std::begin(state_init), std::end(state_init), \
215  0) + \
216  tail) {} \
217  ~add() noexcept {} \
218  add(add&& other) = default; /*NOLINT*/ \
219  Int operator()(int a, int b, int c) qual \
220  ABSL_INTERNAL_NOEXCEPT_SPEC(CallExceptionSpec == NothrowCall::yes) { \
221  return state + a + b + c; \
222  } \
223  int state; \
224  }
225 
226 // Explicitly specify an empty argument.
227 // MSVC (at least up to _MSC_VER 1931, if not beyond) warns that
228 // ABSL_INTERNALS_ADD() is an undefined zero-arg overload.
229 #define ABSL_INTERNALS_NOARG
231 #undef ABSL_INTERNALS_NOARG
232 
233 ABSL_INTERNALS_ADD(const);
235 ABSL_INTERNALS_ADD(const&);
236 ABSL_INTERNALS_ADD(&&); // NOLINT
237 ABSL_INTERNALS_ADD(const&&); // NOLINT
238 
239 #undef ABSL_INTERNALS_ADD
240 
241 template <Destructible Destructibility, class Qual,
242  NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
243 struct add<Movable::no, Destructibility, Qual, CallExceptionSpec, Size,
244  Alignment> : private add<Movable::trivial, Destructibility, Qual,
245  CallExceptionSpec, Size, Alignment> {
246  using Base = add<Movable::trivial, Destructibility, Qual, CallExceptionSpec,
247  Size, Alignment>;
248 
249  explicit add(int state_init) : Base(state_init) {}
250 
251  explicit add(std::initializer_list<int> state_init, int tail)
252  : Base(state_init, tail) {}
253 
254  add(add&&) = delete;
255 
256  using Base::operator();
257  using Base::state;
258 };
259 
260 template <Destructible Destructibility, class Qual,
261  NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
262 struct add<Movable::yes, Destructibility, Qual, CallExceptionSpec, Size,
263  Alignment> : private add<Movable::trivial, Destructibility, Qual,
264  CallExceptionSpec, Size, Alignment> {
265  using Base = add<Movable::trivial, Destructibility, Qual, CallExceptionSpec,
266  Size, Alignment>;
267 
268  explicit add(int state_init) : Base(state_init) {}
269 
270  explicit add(std::initializer_list<int> state_init, int tail)
271  : Base(state_init, tail) {}
272 
273  add(add&& other) noexcept(false) : Base(other.state) {} // NOLINT
274 
275  using Base::operator();
276  using Base::state;
277 };
278 
279 template <Destructible Destructibility, class Qual,
280  NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
281 struct add<Movable::nothrow, Destructibility, Qual, CallExceptionSpec, Size,
282  Alignment> : private add<Movable::trivial, Destructibility, Qual,
283  CallExceptionSpec, Size, Alignment> {
284  using Base = add<Movable::trivial, Destructibility, Qual, CallExceptionSpec,
285  Size, Alignment>;
286 
287  explicit add(int state_init) : Base(state_init) {}
288 
289  explicit add(std::initializer_list<int> state_init, int tail)
290  : Base(state_init, tail) {}
291 
292  add(add&& other) noexcept : Base(other.state) {}
293 
294  using Base::operator();
295  using Base::state;
296 };
297 
298 // Actual non-member functions rather than function objects
299 Int add_function(Int&& a, int b, int c) noexcept { return a.value + b + c; }
300 
301 Int mult_function(Int&& a, int b, int c) noexcept { return a.value * b * c; }
302 
303 Int square_function(Int const&& a) noexcept { return a.value * a.value; }
304 
305 template <class Sig>
306 using AnyInvocable = absl::AnyInvocable<Sig>;
307 
308 // Instantiations of this template contains all of the compile-time parameters
309 // for a given instantiation of the AnyInvocable test suite.
310 template <Movable Movability, Destructible Destructibility, class Qual,
311  NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
312 struct TestParams {
313  static constexpr Movable kMovability = Movability;
314  static constexpr Destructible kDestructibility = Destructibility;
315  using Qualifiers = Qual;
316  static constexpr NothrowCall kCallExceptionSpec = CallExceptionSpec;
317  static constexpr bool kIsNoexcept = kCallExceptionSpec == NothrowCall::yes;
318  static constexpr bool kIsRvalueQualified =
320  static constexpr ObjSize kSize = Size;
321  static constexpr ObjAlign kAlignment = Alignment;
322 
323  // These types are used when testing with member object pointer Invocables
324  using UnqualifiedUnaryFunType = int(Int const&&)
325  ABSL_INTERNAL_NOEXCEPT_SPEC(CallExceptionSpec == NothrowCall::yes);
326  using UnaryFunType = GiveQualifiersToFun<Qualifiers, UnqualifiedUnaryFunType>;
327  using MemObjPtrType = int(Int::*);
328  using UnaryAnyInvType = AnyInvocable<UnaryFunType>;
329  using UnaryThisParamType = QualifiersForThis<Qualifiers, UnaryAnyInvType>;
330 
331  template <class T>
332  static UnaryThisParamType ToUnaryThisParam(T&& fun) {
333  return static_cast<UnaryThisParamType>(fun);
334  }
335 
336  // This function type intentionally uses 3 "kinds" of parameter types.
337  // - A user-defined type
338  // - A reference type
339  // - A scalar type
340  //
341  // These were chosen because internal forwarding takes place on parameters
342  // differently depending based on type properties (scalars are forwarded by
343  // value).
344  using ResultType = Int;
345  using AnyInvocableFunTypeNotNoexcept = Int(Int, const int&, int);
346  using UnqualifiedFunType =
347  typename std::conditional<kIsNoexcept, Int(Int, const int&, int) noexcept,
348  Int(Int, const int&, int)>::type;
349  using FunType = GiveQualifiersToFun<Qualifiers, UnqualifiedFunType>;
350  using MemFunPtrType =
351  typename std::conditional<kIsNoexcept,
352  Int (Int::*)(const int&, int) noexcept,
353  Int (Int::*)(const int&, int)>::type;
354  using AnyInvType = AnyInvocable<FunType>;
355  using AddType = add<kMovability, kDestructibility, Qualifiers,
356  kCallExceptionSpec, kSize, kAlignment>;
357  using ThisParamType = QualifiersForThis<Qualifiers, AnyInvType>;
358 
359  template <class T>
360  static ThisParamType ToThisParam(T&& fun) {
361  return static_cast<ThisParamType>(fun);
362  }
363 
364  // These typedefs are used when testing void return type covariance.
365  using UnqualifiedVoidFunType =
366  typename std::conditional<kIsNoexcept,
367  void(Int, const int&, int) noexcept,
368  void(Int, const int&, int)>::type;
369  using VoidFunType = GiveQualifiersToFun<Qualifiers, UnqualifiedVoidFunType>;
370  using VoidAnyInvType = AnyInvocable<VoidFunType>;
371  using VoidThisParamType = QualifiersForThis<Qualifiers, VoidAnyInvType>;
372 
373  template <class T>
374  static VoidThisParamType ToVoidThisParam(T&& fun) {
375  return static_cast<VoidThisParamType>(fun);
376  }
377 
378  using CompatibleAnyInvocableFunType =
380  GiveQualifiersToFun<const _&&, UnqualifiedFunType>,
381  GiveQualifiersToFun<const _&, UnqualifiedFunType>>;
382 
383  using CompatibleAnyInvType = AnyInvocable<CompatibleAnyInvocableFunType>;
384 
385  using IncompatibleInvocable =
387  GiveQualifiersToFun<_&, UnqualifiedFunType>(_::*),
388  GiveQualifiersToFun<_&&, UnqualifiedFunType>(_::*)>;
389 };
390 
391 // Given a member-pointer type, this metafunction yields the target type of the
392 // pointer, not including the class-type. It is used to verify that the function
393 // call operator of AnyInvocable has the proper signature, corresponding to the
394 // function type that the user provided.
395 template <class MemberPtrType>
396 struct MemberTypeOfImpl;
397 
398 template <class Class, class T>
399 struct MemberTypeOfImpl<T(Class::*)> {
400  using type = T;
401 };
402 
403 template <class MemberPtrType>
404 using MemberTypeOf = typename MemberTypeOfImpl<MemberPtrType>::type;
405 
406 template <class T, class = void>
407 struct IsMemberSwappableImpl : std::false_type {
408  static constexpr bool kIsNothrow = false;
409 };
410 
411 template <class T>
412 struct IsMemberSwappableImpl<
413  T, absl::void_t<decltype(std::declval<T&>().swap(std::declval<T&>()))>>
414  : std::true_type {
415  static constexpr bool kIsNothrow =
416  noexcept(std::declval<T&>().swap(std::declval<T&>()));
417 };
418 
419 template <class T>
420 using IsMemberSwappable = IsMemberSwappableImpl<T>;
421 
422 template <class T>
423 using IsNothrowMemberSwappable =
424  std::integral_constant<bool, IsMemberSwappableImpl<T>::kIsNothrow>;
425 
426 template <class T>
427 class AnyInvTestBasic : public ::testing::Test {};
428 
429 TYPED_TEST_SUITE_P(AnyInvTestBasic);
430 
431 TYPED_TEST_P(AnyInvTestBasic, DefaultConstruction) {
432  using AnyInvType = typename TypeParam::AnyInvType;
433 
434  AnyInvType fun;
435 
436  EXPECT_FALSE(static_cast<bool>(fun));
437 
439 }
440 
441 TYPED_TEST_P(AnyInvTestBasic, ConstructionNullptr) {
442  using AnyInvType = typename TypeParam::AnyInvType;
443 
444  AnyInvType fun = nullptr;
445 
446  EXPECT_FALSE(static_cast<bool>(fun));
447 
448  EXPECT_TRUE(
450 }
451 
452 TYPED_TEST_P(AnyInvTestBasic, ConstructionNullFunctionPtr) {
453  using AnyInvType = typename TypeParam::AnyInvType;
454  using UnqualifiedFunType = typename TypeParam::UnqualifiedFunType;
455 
456  UnqualifiedFunType* const null_fun_ptr = nullptr;
457  AnyInvType fun = null_fun_ptr;
458 
459  EXPECT_FALSE(static_cast<bool>(fun));
460 }
461 
462 TYPED_TEST_P(AnyInvTestBasic, ConstructionNullMemberFunctionPtr) {
463  using AnyInvType = typename TypeParam::AnyInvType;
464  using MemFunPtrType = typename TypeParam::MemFunPtrType;
465 
466  const MemFunPtrType null_mem_fun_ptr = nullptr;
467  AnyInvType fun = null_mem_fun_ptr;
468 
469  EXPECT_FALSE(static_cast<bool>(fun));
470 }
471 
472 TYPED_TEST_P(AnyInvTestBasic, ConstructionNullMemberObjectPtr) {
473  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
474  using MemObjPtrType = typename TypeParam::MemObjPtrType;
475 
476  const MemObjPtrType null_mem_obj_ptr = nullptr;
477  UnaryAnyInvType fun = null_mem_obj_ptr;
478 
479  EXPECT_FALSE(static_cast<bool>(fun));
480 }
481 
482 TYPED_TEST_P(AnyInvTestBasic, ConstructionMemberFunctionPtr) {
483  using AnyInvType = typename TypeParam::AnyInvType;
484 
485  AnyInvType fun = &Int::MemberFunctionAdd;
486 
487  EXPECT_TRUE(static_cast<bool>(fun));
488  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
489 }
490 
491 TYPED_TEST_P(AnyInvTestBasic, ConstructionMemberObjectPtr) {
492  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
493 
494  UnaryAnyInvType fun = &Int::value;
495 
496  EXPECT_TRUE(static_cast<bool>(fun));
497  EXPECT_EQ(13, TypeParam::ToUnaryThisParam(fun)(13));
498 }
499 
500 TYPED_TEST_P(AnyInvTestBasic, ConstructionFunctionReferenceDecay) {
501  using AnyInvType = typename TypeParam::AnyInvType;
502 
503  AnyInvType fun = add_function;
504 
505  EXPECT_TRUE(static_cast<bool>(fun));
506  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
507 }
508 
509 TYPED_TEST_P(AnyInvTestBasic, ConstructionCompatibleAnyInvocableEmpty) {
510  using AnyInvType = typename TypeParam::AnyInvType;
511  using CompatibleAnyInvType = typename TypeParam::CompatibleAnyInvType;
512 
513  CompatibleAnyInvType other;
514  AnyInvType fun = std::move(other);
515 
516  EXPECT_FALSE(static_cast<bool>(other)); // NOLINT
517  EXPECT_EQ(other, nullptr); // NOLINT
518  EXPECT_EQ(nullptr, other); // NOLINT
519 
520  EXPECT_FALSE(static_cast<bool>(fun));
521 }
522 
523 TYPED_TEST_P(AnyInvTestBasic, ConstructionCompatibleAnyInvocableNonempty) {
524  using AnyInvType = typename TypeParam::AnyInvType;
525  using CompatibleAnyInvType = typename TypeParam::CompatibleAnyInvType;
526 
527  CompatibleAnyInvType other = &add_function;
528  AnyInvType fun = std::move(other);
529 
530  EXPECT_FALSE(static_cast<bool>(other)); // NOLINT
531  EXPECT_EQ(other, nullptr); // NOLINT
532  EXPECT_EQ(nullptr, other); // NOLINT
533 
534  EXPECT_TRUE(static_cast<bool>(fun));
535  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
536 }
537 
538 TYPED_TEST_P(AnyInvTestBasic, ConversionToBool) {
539  using AnyInvType = typename TypeParam::AnyInvType;
540 
541  {
542  AnyInvType fun;
543 
544  // This tests contextually-convertible-to-bool.
545  EXPECT_FALSE(fun ? true : false); // NOLINT
546 
547  // Make sure that the conversion is not implicit.
548  EXPECT_TRUE(
551  }
552 
553  {
554  AnyInvType fun = &add_function;
555 
556  // This tests contextually-convertible-to-bool.
557  EXPECT_TRUE(fun ? true : false); // NOLINT
558  }
559 }
560 
561 TYPED_TEST_P(AnyInvTestBasic, Invocation) {
562  using AnyInvType = typename TypeParam::AnyInvType;
563 
564  using FunType = typename TypeParam::FunType;
565  using AnyInvCallType = MemberTypeOf<decltype(&AnyInvType::operator())>;
566 
567  // Make sure the function call operator of AnyInvocable always has the
568  // type that was specified via the template argument.
570 
571  AnyInvType fun = &add_function;
572 
573  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
574 }
575 
576 TYPED_TEST_P(AnyInvTestBasic, InPlaceConstruction) {
577  using AnyInvType = typename TypeParam::AnyInvType;
578  using AddType = typename TypeParam::AddType;
579 
580  AnyInvType fun(absl::in_place_type<AddType>, 5);
581 
582  EXPECT_TRUE(static_cast<bool>(fun));
583  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
584 }
585 
586 TYPED_TEST_P(AnyInvTestBasic, InPlaceConstructionInitializerList) {
587  using AnyInvType = typename TypeParam::AnyInvType;
588  using AddType = typename TypeParam::AddType;
589 
590  AnyInvType fun(absl::in_place_type<AddType>, {1, 2, 3, 4}, 5);
591 
592  EXPECT_TRUE(static_cast<bool>(fun));
593  EXPECT_EQ(39, TypeParam::ToThisParam(fun)(7, 8, 9).value);
594 }
595 
596 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullFunPtrConstruction) {
597  using AnyInvType = typename TypeParam::AnyInvType;
598  using UnqualifiedFunType = typename TypeParam::UnqualifiedFunType;
599 
600  AnyInvType fun(absl::in_place_type<UnqualifiedFunType*>, nullptr);
601 
602  // In-place construction does not lead to empty.
603  EXPECT_TRUE(static_cast<bool>(fun));
604 }
605 
606 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullFunPtrConstructionValueInit) {
607  using AnyInvType = typename TypeParam::AnyInvType;
608  using UnqualifiedFunType = typename TypeParam::UnqualifiedFunType;
609 
610  AnyInvType fun(absl::in_place_type<UnqualifiedFunType*>);
611 
612  // In-place construction does not lead to empty.
613  EXPECT_TRUE(static_cast<bool>(fun));
614 }
615 
616 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemFunPtrConstruction) {
617  using AnyInvType = typename TypeParam::AnyInvType;
618  using MemFunPtrType = typename TypeParam::MemFunPtrType;
619 
620  AnyInvType fun(absl::in_place_type<MemFunPtrType>, nullptr);
621 
622  // In-place construction does not lead to empty.
623  EXPECT_TRUE(static_cast<bool>(fun));
624 }
625 
626 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemFunPtrConstructionValueInit) {
627  using AnyInvType = typename TypeParam::AnyInvType;
628  using MemFunPtrType = typename TypeParam::MemFunPtrType;
629 
630  AnyInvType fun(absl::in_place_type<MemFunPtrType>);
631 
632  // In-place construction does not lead to empty.
633  EXPECT_TRUE(static_cast<bool>(fun));
634 }
635 
636 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemObjPtrConstruction) {
637  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
638  using MemObjPtrType = typename TypeParam::MemObjPtrType;
639 
640  UnaryAnyInvType fun(absl::in_place_type<MemObjPtrType>, nullptr);
641 
642  // In-place construction does not lead to empty.
643  EXPECT_TRUE(static_cast<bool>(fun));
644 }
645 
646 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemObjPtrConstructionValueInit) {
647  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
648  using MemObjPtrType = typename TypeParam::MemObjPtrType;
649 
650  UnaryAnyInvType fun(absl::in_place_type<MemObjPtrType>);
651 
652  // In-place construction does not lead to empty.
653  EXPECT_TRUE(static_cast<bool>(fun));
654 }
655 
656 TYPED_TEST_P(AnyInvTestBasic, InPlaceVoidCovarianceConstruction) {
657  using VoidAnyInvType = typename TypeParam::VoidAnyInvType;
658  using AddType = typename TypeParam::AddType;
659 
660  VoidAnyInvType fun(absl::in_place_type<AddType>, 5);
661 
662  EXPECT_TRUE(static_cast<bool>(fun));
663 }
664 
665 TYPED_TEST_P(AnyInvTestBasic, MoveConstructionFromEmpty) {
666  using AnyInvType = typename TypeParam::AnyInvType;
667 
668  AnyInvType source_fun;
669  AnyInvType fun(std::move(source_fun));
670 
671  EXPECT_FALSE(static_cast<bool>(fun));
672 
674 }
675 
676 TYPED_TEST_P(AnyInvTestBasic, MoveConstructionFromNonEmpty) {
677  using AnyInvType = typename TypeParam::AnyInvType;
678  using AddType = typename TypeParam::AddType;
679 
680  AnyInvType source_fun(absl::in_place_type<AddType>, 5);
681  AnyInvType fun(std::move(source_fun));
682 
683  EXPECT_TRUE(static_cast<bool>(fun));
684  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
685 
687 }
688 
689 TYPED_TEST_P(AnyInvTestBasic, ComparisonWithNullptrEmpty) {
690  using AnyInvType = typename TypeParam::AnyInvType;
691 
692  AnyInvType fun;
693 
694  EXPECT_TRUE(fun == nullptr);
695  EXPECT_TRUE(nullptr == fun);
696 
697  EXPECT_FALSE(fun != nullptr);
698  EXPECT_FALSE(nullptr != fun);
699 }
700 
701 TYPED_TEST_P(AnyInvTestBasic, ComparisonWithNullptrNonempty) {
702  using AnyInvType = typename TypeParam::AnyInvType;
703  using AddType = typename TypeParam::AddType;
704 
705  AnyInvType fun(absl::in_place_type<AddType>, 5);
706 
707  EXPECT_FALSE(fun == nullptr);
708  EXPECT_FALSE(nullptr == fun);
709 
710  EXPECT_TRUE(fun != nullptr);
711  EXPECT_TRUE(nullptr != fun);
712 }
713 
714 TYPED_TEST_P(AnyInvTestBasic, ResultType) {
715  using AnyInvType = typename TypeParam::AnyInvType;
716  using ExpectedResultType = typename TypeParam::ResultType;
717 
718  EXPECT_TRUE((std::is_same<typename AnyInvType::result_type,
719  ExpectedResultType>::value));
720 }
721 
722 template <class T>
723 class AnyInvTestCombinatoric : public ::testing::Test {};
724 
725 TYPED_TEST_SUITE_P(AnyInvTestCombinatoric);
726 
727 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignEmptyEmptyLhsRhs) {
728  using AnyInvType = typename TypeParam::AnyInvType;
729 
730  AnyInvType source_fun;
731  AnyInvType fun;
732 
733  fun = std::move(source_fun);
734 
735  EXPECT_FALSE(static_cast<bool>(fun));
736 }
737 
738 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignEmptyLhsNonemptyRhs) {
739  using AnyInvType = typename TypeParam::AnyInvType;
740  using AddType = typename TypeParam::AddType;
741 
742  AnyInvType source_fun(absl::in_place_type<AddType>, 5);
743  AnyInvType fun;
744 
745  fun = std::move(source_fun);
746 
747  EXPECT_TRUE(static_cast<bool>(fun));
748  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
749 }
750 
751 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignNonemptyEmptyLhsRhs) {
752  using AnyInvType = typename TypeParam::AnyInvType;
753  using AddType = typename TypeParam::AddType;
754 
755  AnyInvType source_fun;
756  AnyInvType fun(absl::in_place_type<AddType>, 5);
757 
758  fun = std::move(source_fun);
759 
760  EXPECT_FALSE(static_cast<bool>(fun));
761 }
762 
763 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignNonemptyLhsNonemptyRhs) {
764  using AnyInvType = typename TypeParam::AnyInvType;
765  using AddType = typename TypeParam::AddType;
766 
767  AnyInvType source_fun(absl::in_place_type<AddType>, 5);
768  AnyInvType fun(absl::in_place_type<AddType>, 20);
769 
770  fun = std::move(source_fun);
771 
772  EXPECT_TRUE(static_cast<bool>(fun));
773  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
774 }
775 
776 TYPED_TEST_P(AnyInvTestCombinatoric, SelfMoveAssignEmpty) {
777  using AnyInvType = typename TypeParam::AnyInvType;
778 
779  AnyInvType source_fun;
780  source_fun = std::move(source_fun);
781 
782  // This space intentionally left blank.
783 }
784 
785 TYPED_TEST_P(AnyInvTestCombinatoric, SelfMoveAssignNonempty) {
786  using AnyInvType = typename TypeParam::AnyInvType;
787  using AddType = typename TypeParam::AddType;
788 
789  AnyInvType source_fun(absl::in_place_type<AddType>, 5);
790  source_fun = std::move(source_fun);
791 
792  // This space intentionally left blank.
793 }
794 
795 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullptrEmptyLhs) {
796  using AnyInvType = typename TypeParam::AnyInvType;
797 
798  AnyInvType fun;
799  fun = nullptr;
800 
801  EXPECT_FALSE(static_cast<bool>(fun));
802 }
803 
804 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullFunctionPtrEmptyLhs) {
805  using AnyInvType = typename TypeParam::AnyInvType;
806  using UnqualifiedFunType = typename TypeParam::UnqualifiedFunType;
807 
808  UnqualifiedFunType* const null_fun_ptr = nullptr;
809  AnyInvType fun;
810  fun = null_fun_ptr;
811 
812  EXPECT_FALSE(static_cast<bool>(fun));
813 }
814 
815 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberFunctionPtrEmptyLhs) {
816  using AnyInvType = typename TypeParam::AnyInvType;
817  using MemFunPtrType = typename TypeParam::MemFunPtrType;
818 
819  const MemFunPtrType null_mem_fun_ptr = nullptr;
820  AnyInvType fun;
821  fun = null_mem_fun_ptr;
822 
823  EXPECT_FALSE(static_cast<bool>(fun));
824 }
825 
826 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberObjectPtrEmptyLhs) {
827  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
828  using MemObjPtrType = typename TypeParam::MemObjPtrType;
829 
830  const MemObjPtrType null_mem_obj_ptr = nullptr;
831  UnaryAnyInvType fun;
832  fun = null_mem_obj_ptr;
833 
834  EXPECT_FALSE(static_cast<bool>(fun));
835 }
836 
837 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberFunctionPtrEmptyLhs) {
838  using AnyInvType = typename TypeParam::AnyInvType;
839 
840  AnyInvType fun;
841  fun = &Int::MemberFunctionAdd;
842 
843  EXPECT_TRUE(static_cast<bool>(fun));
844  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
845 }
846 
847 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberObjectPtrEmptyLhs) {
848  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
849 
850  UnaryAnyInvType fun;
851  fun = &Int::value;
852 
853  EXPECT_TRUE(static_cast<bool>(fun));
854  EXPECT_EQ(13, TypeParam::ToUnaryThisParam(fun)(13));
855 }
856 
857 TYPED_TEST_P(AnyInvTestCombinatoric, AssignFunctionReferenceDecayEmptyLhs) {
858  using AnyInvType = typename TypeParam::AnyInvType;
859 
860  AnyInvType fun;
861  fun = add_function;
862 
863  EXPECT_TRUE(static_cast<bool>(fun));
864  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
865 }
866 
867 TYPED_TEST_P(AnyInvTestCombinatoric,
868  AssignCompatibleAnyInvocableEmptyLhsEmptyRhs) {
869  using AnyInvType = typename TypeParam::AnyInvType;
870  using CompatibleAnyInvType = typename TypeParam::CompatibleAnyInvType;
871 
872  CompatibleAnyInvType other;
873  AnyInvType fun;
874  fun = std::move(other);
875 
876  EXPECT_FALSE(static_cast<bool>(other)); // NOLINT
877  EXPECT_EQ(other, nullptr); // NOLINT
878  EXPECT_EQ(nullptr, other); // NOLINT
879 
880  EXPECT_FALSE(static_cast<bool>(fun));
881 }
882 
883 TYPED_TEST_P(AnyInvTestCombinatoric,
884  AssignCompatibleAnyInvocableEmptyLhsNonemptyRhs) {
885  using AnyInvType = typename TypeParam::AnyInvType;
886  using CompatibleAnyInvType = typename TypeParam::CompatibleAnyInvType;
887 
888  CompatibleAnyInvType other = &add_function;
889  AnyInvType fun;
890  fun = std::move(other);
891 
892  EXPECT_FALSE(static_cast<bool>(other)); // NOLINT
893 
894  EXPECT_TRUE(static_cast<bool>(fun));
895  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
896 }
897 
898 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullptrNonemptyLhs) {
899  using AnyInvType = typename TypeParam::AnyInvType;
900 
901  AnyInvType fun = &mult_function;
902  fun = nullptr;
903 
904  EXPECT_FALSE(static_cast<bool>(fun));
905 }
906 
907 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullFunctionPtrNonemptyLhs) {
908  using AnyInvType = typename TypeParam::AnyInvType;
909  using UnqualifiedFunType = typename TypeParam::UnqualifiedFunType;
910 
911  UnqualifiedFunType* const null_fun_ptr = nullptr;
912  AnyInvType fun = &mult_function;
913  fun = null_fun_ptr;
914 
915  EXPECT_FALSE(static_cast<bool>(fun));
916 }
917 
918 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberFunctionPtrNonemptyLhs) {
919  using AnyInvType = typename TypeParam::AnyInvType;
920  using MemFunPtrType = typename TypeParam::MemFunPtrType;
921 
922  const MemFunPtrType null_mem_fun_ptr = nullptr;
923  AnyInvType fun = &mult_function;
924  fun = null_mem_fun_ptr;
925 
926  EXPECT_FALSE(static_cast<bool>(fun));
927 }
928 
929 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberObjectPtrNonemptyLhs) {
930  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
931  using MemObjPtrType = typename TypeParam::MemObjPtrType;
932 
933  const MemObjPtrType null_mem_obj_ptr = nullptr;
934  UnaryAnyInvType fun = &square_function;
935  fun = null_mem_obj_ptr;
936 
937  EXPECT_FALSE(static_cast<bool>(fun));
938 }
939 
940 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberFunctionPtrNonemptyLhs) {
941  using AnyInvType = typename TypeParam::AnyInvType;
942 
943  AnyInvType fun = &mult_function;
944  fun = &Int::MemberFunctionAdd;
945 
946  EXPECT_TRUE(static_cast<bool>(fun));
947  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
948 }
949 
950 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberObjectPtrNonemptyLhs) {
951  using UnaryAnyInvType = typename TypeParam::UnaryAnyInvType;
952 
953  UnaryAnyInvType fun = &square_function;
954  fun = &Int::value;
955 
956  EXPECT_TRUE(static_cast<bool>(fun));
957  EXPECT_EQ(13, TypeParam::ToUnaryThisParam(fun)(13));
958 }
959 
960 TYPED_TEST_P(AnyInvTestCombinatoric, AssignFunctionReferenceDecayNonemptyLhs) {
961  using AnyInvType = typename TypeParam::AnyInvType;
962 
963  AnyInvType fun = &mult_function;
964  fun = add_function;
965 
966  EXPECT_TRUE(static_cast<bool>(fun));
967  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
968 }
969 
970 TYPED_TEST_P(AnyInvTestCombinatoric,
971  AssignCompatibleAnyInvocableNonemptyLhsEmptyRhs) {
972  using AnyInvType = typename TypeParam::AnyInvType;
973  using CompatibleAnyInvType = typename TypeParam::CompatibleAnyInvType;
974 
975  CompatibleAnyInvType other;
976  AnyInvType fun = &mult_function;
977  fun = std::move(other);
978 
979  EXPECT_FALSE(static_cast<bool>(other)); // NOLINT
980  EXPECT_EQ(other, nullptr); // NOLINT
981  EXPECT_EQ(nullptr, other); // NOLINT
982 
983  EXPECT_FALSE(static_cast<bool>(fun));
984 }
985 
986 TYPED_TEST_P(AnyInvTestCombinatoric,
987  AssignCompatibleAnyInvocableNonemptyLhsNonemptyRhs) {
988  using AnyInvType = typename TypeParam::AnyInvType;
989  using CompatibleAnyInvType = typename TypeParam::CompatibleAnyInvType;
990 
991  CompatibleAnyInvType other = &add_function;
992  AnyInvType fun = &mult_function;
993  fun = std::move(other);
994 
995  EXPECT_FALSE(static_cast<bool>(other)); // NOLINT
996 
997  EXPECT_TRUE(static_cast<bool>(fun));
998  EXPECT_EQ(24, TypeParam::ToThisParam(fun)(7, 8, 9).value);
999 }
1000 
1001 TYPED_TEST_P(AnyInvTestCombinatoric, SwapEmptyLhsEmptyRhs) {
1002  using AnyInvType = typename TypeParam::AnyInvType;
1003 
1004  // Swap idiom
1005  {
1006  AnyInvType fun;
1007  AnyInvType other;
1008 
1009  using std::swap;
1010  swap(fun, other);
1011 
1012  EXPECT_FALSE(static_cast<bool>(fun));
1013  EXPECT_FALSE(static_cast<bool>(other));
1014 
1015  EXPECT_TRUE(
1017  }
1018 
1019  // Member swap
1020  {
1021  AnyInvType fun;
1022  AnyInvType other;
1023 
1024  fun.swap(other);
1025 
1026  EXPECT_FALSE(static_cast<bool>(fun));
1027  EXPECT_FALSE(static_cast<bool>(other));
1028 
1030  }
1031 }
1032 
1033 TYPED_TEST_P(AnyInvTestCombinatoric, SwapEmptyLhsNonemptyRhs) {
1034  using AnyInvType = typename TypeParam::AnyInvType;
1035  using AddType = typename TypeParam::AddType;
1036 
1037  // Swap idiom
1038  {
1039  AnyInvType fun;
1040  AnyInvType other(absl::in_place_type<AddType>, 5);
1041 
1042  using std::swap;
1043  swap(fun, other);
1044 
1045  EXPECT_TRUE(static_cast<bool>(fun));
1046  EXPECT_FALSE(static_cast<bool>(other));
1047 
1048  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1049 
1050  EXPECT_TRUE(
1052  }
1053 
1054  // Member swap
1055  {
1056  AnyInvType fun;
1057  AnyInvType other(absl::in_place_type<AddType>, 5);
1058 
1059  fun.swap(other);
1060 
1061  EXPECT_TRUE(static_cast<bool>(fun));
1062  EXPECT_FALSE(static_cast<bool>(other));
1063 
1064  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1065 
1067  }
1068 }
1069 
1070 TYPED_TEST_P(AnyInvTestCombinatoric, SwapNonemptyLhsEmptyRhs) {
1071  using AnyInvType = typename TypeParam::AnyInvType;
1072  using AddType = typename TypeParam::AddType;
1073 
1074  // Swap idiom
1075  {
1076  AnyInvType fun(absl::in_place_type<AddType>, 5);
1077  AnyInvType other;
1078 
1079  using std::swap;
1080  swap(fun, other);
1081 
1082  EXPECT_FALSE(static_cast<bool>(fun));
1083  EXPECT_TRUE(static_cast<bool>(other));
1084 
1085  EXPECT_EQ(29, TypeParam::ToThisParam(other)(7, 8, 9).value);
1086 
1087  EXPECT_TRUE(
1089  }
1090 
1091  // Member swap
1092  {
1093  AnyInvType fun(absl::in_place_type<AddType>, 5);
1094  AnyInvType other;
1095 
1096  fun.swap(other);
1097 
1098  EXPECT_FALSE(static_cast<bool>(fun));
1099  EXPECT_TRUE(static_cast<bool>(other));
1100 
1101  EXPECT_EQ(29, TypeParam::ToThisParam(other)(7, 8, 9).value);
1102 
1104  }
1105 }
1106 
1107 TYPED_TEST_P(AnyInvTestCombinatoric, SwapNonemptyLhsNonemptyRhs) {
1108  using AnyInvType = typename TypeParam::AnyInvType;
1109  using AddType = typename TypeParam::AddType;
1110 
1111  // Swap idiom
1112  {
1113  AnyInvType fun(absl::in_place_type<AddType>, 5);
1114  AnyInvType other(absl::in_place_type<AddType>, 6);
1115 
1116  using std::swap;
1117  swap(fun, other);
1118 
1119  EXPECT_TRUE(static_cast<bool>(fun));
1120  EXPECT_TRUE(static_cast<bool>(other));
1121 
1122  EXPECT_EQ(30, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1123  EXPECT_EQ(29, TypeParam::ToThisParam(other)(7, 8, 9).value);
1124 
1125  EXPECT_TRUE(
1127  }
1128 
1129  // Member swap
1130  {
1131  AnyInvType fun(absl::in_place_type<AddType>, 5);
1132  AnyInvType other(absl::in_place_type<AddType>, 6);
1133 
1134  fun.swap(other);
1135 
1136  EXPECT_TRUE(static_cast<bool>(fun));
1137  EXPECT_TRUE(static_cast<bool>(other));
1138 
1139  EXPECT_EQ(30, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1140  EXPECT_EQ(29, TypeParam::ToThisParam(other)(7, 8, 9).value);
1141 
1143  }
1144 }
1145 
1146 template <class T>
1147 class AnyInvTestMovable : public ::testing::Test {};
1148 
1149 TYPED_TEST_SUITE_P(AnyInvTestMovable);
1150 
1151 TYPED_TEST_P(AnyInvTestMovable, ConversionConstructionUserDefinedType) {
1152  using AnyInvType = typename TypeParam::AnyInvType;
1153  using AddType = typename TypeParam::AddType;
1154 
1155  AnyInvType fun(AddType(5));
1156 
1157  EXPECT_TRUE(static_cast<bool>(fun));
1158  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1159 
1160  EXPECT_TRUE(static_cast<bool>(fun));
1161  EXPECT_EQ(38, TypeParam::ToThisParam(fun)(10, 11, 12).value);
1162 }
1163 
1164 TYPED_TEST_P(AnyInvTestMovable, ConversionConstructionVoidCovariance) {
1165  using VoidAnyInvType = typename TypeParam::VoidAnyInvType;
1166  using AddType = typename TypeParam::AddType;
1167 
1168  VoidAnyInvType fun(AddType(5));
1169 
1170  EXPECT_TRUE(static_cast<bool>(fun));
1171 }
1172 
1173 TYPED_TEST_P(AnyInvTestMovable, ConversionAssignUserDefinedTypeEmptyLhs) {
1174  using AnyInvType = typename TypeParam::AnyInvType;
1175  using AddType = typename TypeParam::AddType;
1176 
1177  AnyInvType fun;
1178  fun = AddType(5);
1179 
1180  EXPECT_TRUE(static_cast<bool>(fun));
1181  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1182 
1183  EXPECT_TRUE(static_cast<bool>(fun));
1184  EXPECT_EQ(38, TypeParam::ToThisParam(fun)(10, 11, 12).value);
1185 }
1186 
1187 TYPED_TEST_P(AnyInvTestMovable, ConversionAssignUserDefinedTypeNonemptyLhs) {
1188  using AnyInvType = typename TypeParam::AnyInvType;
1189  using AddType = typename TypeParam::AddType;
1190 
1191  AnyInvType fun = &add_function;
1192  fun = AddType(5);
1193 
1194  EXPECT_TRUE(static_cast<bool>(fun));
1195  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1196 
1197  EXPECT_TRUE(static_cast<bool>(fun));
1198  EXPECT_EQ(38, TypeParam::ToThisParam(fun)(10, 11, 12).value);
1199 }
1200 
1201 TYPED_TEST_P(AnyInvTestMovable, ConversionAssignVoidCovariance) {
1202  using VoidAnyInvType = typename TypeParam::VoidAnyInvType;
1203  using AddType = typename TypeParam::AddType;
1204 
1205  VoidAnyInvType fun;
1206  fun = AddType(5);
1207 
1208  EXPECT_TRUE(static_cast<bool>(fun));
1209 }
1210 
1211 template <class T>
1212 class AnyInvTestNoexceptFalse : public ::testing::Test {};
1213 
1214 TYPED_TEST_SUITE_P(AnyInvTestNoexceptFalse);
1215 
1216 TYPED_TEST_P(AnyInvTestNoexceptFalse, ConversionConstructionConstraints) {
1217  using AnyInvType = typename TypeParam::AnyInvType;
1218 
1219  EXPECT_TRUE((std::is_constructible<
1220  AnyInvType,
1221  typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::value));
1222  EXPECT_FALSE((
1223  std::is_constructible<AnyInvType,
1224  typename TypeParam::IncompatibleInvocable>::value));
1225 }
1226 
1227 TYPED_TEST_P(AnyInvTestNoexceptFalse, ConversionAssignConstraints) {
1228  using AnyInvType = typename TypeParam::AnyInvType;
1229 
1230  EXPECT_TRUE((std::is_assignable<
1231  AnyInvType&,
1232  typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::value));
1233  EXPECT_FALSE(
1234  (std::is_assignable<AnyInvType&,
1235  typename TypeParam::IncompatibleInvocable>::value));
1236 }
1237 
1238 template <class T>
1239 class AnyInvTestNoexceptTrue : public ::testing::Test {};
1240 
1241 TYPED_TEST_SUITE_P(AnyInvTestNoexceptTrue);
1242 
1243 TYPED_TEST_P(AnyInvTestNoexceptTrue, ConversionConstructionConstraints) {
1244 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1245  GTEST_SKIP() << "Noexcept was not part of the type system before C++17.";
1246 #else
1247  using AnyInvType = typename TypeParam::AnyInvType;
1248 
1249 // TODO(b/217761454): Fix this and re-enable for MSVC.
1250 #ifndef _MSC_VER
1251  EXPECT_FALSE((std::is_constructible<
1252  AnyInvType,
1253  typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::value));
1254 #endif
1255  EXPECT_FALSE((
1256  std::is_constructible<AnyInvType,
1257  typename TypeParam::IncompatibleInvocable>::value));
1258 #endif
1259 }
1260 
1261 TYPED_TEST_P(AnyInvTestNoexceptTrue, ConversionAssignConstraints) {
1262 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1263  GTEST_SKIP() << "Noexcept was not part of the type system before C++17.";
1264 #else
1265  using AnyInvType = typename TypeParam::AnyInvType;
1266 
1267 // TODO(b/217761454): Fix this and re-enable for MSVC.
1268 #ifndef _MSC_VER
1269  EXPECT_FALSE((std::is_assignable<
1270  AnyInvType&,
1271  typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::value));
1272 #endif
1273  EXPECT_FALSE(
1274  (std::is_assignable<AnyInvType&,
1275  typename TypeParam::IncompatibleInvocable>::value));
1276 #endif
1277 }
1278 
1279 template <class T>
1280 class AnyInvTestNonRvalue : public ::testing::Test {};
1281 
1282 TYPED_TEST_SUITE_P(AnyInvTestNonRvalue);
1283 
1284 TYPED_TEST_P(AnyInvTestNonRvalue, ConversionConstructionReferenceWrapper) {
1285  using AnyInvType = typename TypeParam::AnyInvType;
1286  using AddType = typename TypeParam::AddType;
1287 
1288  AddType add(4);
1289  AnyInvType fun = std::ref(add);
1290  add.state = 5;
1291 
1292  EXPECT_TRUE(static_cast<bool>(fun));
1293  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1294 
1295  EXPECT_TRUE(static_cast<bool>(fun));
1296  EXPECT_EQ(38, TypeParam::ToThisParam(fun)(10, 11, 12).value);
1297 }
1298 
1299 TYPED_TEST_P(AnyInvTestNonRvalue, NonMoveableResultType) {
1300 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1301  GTEST_SKIP() << "Copy/move elision was not standard before C++17";
1302 #else
1303  // Define a result type that cannot be copy- or move-constructed.
1304  struct Result {
1305  int x;
1306 
1307  explicit Result(const int x_in) : x(x_in) {}
1308  Result(Result&&) = delete;
1309  };
1310 
1311  static_assert(!std::is_move_constructible<Result>::value, "");
1312  static_assert(!std::is_copy_constructible<Result>::value, "");
1313 
1314  // Assumption check: it should nevertheless be possible to use functors that
1315  // return a Result struct according to the language rules.
1316  const auto return_17 = []() noexcept { return Result(17); };
1317  EXPECT_EQ(17, return_17().x);
1318 
1319  // Just like plain functors, it should work fine to use an AnyInvocable that
1320  // returns the non-moveable type.
1321  using UnqualifiedFun =
1322  absl::conditional_t<TypeParam::kIsNoexcept, Result() noexcept, Result()>;
1323 
1324  using Fun =
1325  GiveQualifiersToFun<typename TypeParam::Qualifiers, UnqualifiedFun>;
1326 
1327  AnyInvocable<Fun> any_inv(return_17);
1328  EXPECT_EQ(17, any_inv().x);
1329 #endif
1330 }
1331 
1332 TYPED_TEST_P(AnyInvTestNonRvalue, ConversionAssignReferenceWrapperEmptyLhs) {
1333  using AnyInvType = typename TypeParam::AnyInvType;
1334  using AddType = typename TypeParam::AddType;
1335 
1336  AddType add(4);
1337  AnyInvType fun;
1338  fun = std::ref(add);
1339  add.state = 5;
1340  EXPECT_TRUE(
1341  (std::is_nothrow_assignable<AnyInvType&,
1342  std::reference_wrapper<AddType>>::value));
1343 
1344  EXPECT_TRUE(static_cast<bool>(fun));
1345  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1346 
1347  EXPECT_TRUE(static_cast<bool>(fun));
1348  EXPECT_EQ(38, TypeParam::ToThisParam(fun)(10, 11, 12).value);
1349 }
1350 
1351 TYPED_TEST_P(AnyInvTestNonRvalue, ConversionAssignReferenceWrapperNonemptyLhs) {
1352  using AnyInvType = typename TypeParam::AnyInvType;
1353  using AddType = typename TypeParam::AddType;
1354 
1355  AddType add(4);
1356  AnyInvType fun = &mult_function;
1357  fun = std::ref(add);
1358  add.state = 5;
1359  EXPECT_TRUE(
1360  (std::is_nothrow_assignable<AnyInvType&,
1361  std::reference_wrapper<AddType>>::value));
1362 
1363  EXPECT_TRUE(static_cast<bool>(fun));
1364  EXPECT_EQ(29, TypeParam::ToThisParam(fun)(7, 8, 9).value);
1365 
1366  EXPECT_TRUE(static_cast<bool>(fun));
1367  EXPECT_EQ(38, TypeParam::ToThisParam(fun)(10, 11, 12).value);
1368 }
1369 
1370 template <class T>
1371 class AnyInvTestRvalue : public ::testing::Test {};
1372 
1373 TYPED_TEST_SUITE_P(AnyInvTestRvalue);
1374 
1375 TYPED_TEST_P(AnyInvTestRvalue, ConversionConstructionReferenceWrapper) {
1376  using AnyInvType = typename TypeParam::AnyInvType;
1377  using AddType = typename TypeParam::AddType;
1378 
1379  EXPECT_FALSE((
1380  std::is_convertible<std::reference_wrapper<AddType>, AnyInvType>::value));
1381 }
1382 
1383 TYPED_TEST_P(AnyInvTestRvalue, NonMoveableResultType) {
1384 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1385  GTEST_SKIP() << "Copy/move elision was not standard before C++17";
1386 #else
1387  // Define a result type that cannot be copy- or move-constructed.
1388  struct Result {
1389  int x;
1390 
1391  explicit Result(const int x_in) : x(x_in) {}
1392  Result(Result&&) = delete;
1393  };
1394 
1395  static_assert(!std::is_move_constructible<Result>::value, "");
1396  static_assert(!std::is_copy_constructible<Result>::value, "");
1397 
1398  // Assumption check: it should nevertheless be possible to use functors that
1399  // return a Result struct according to the language rules.
1400  const auto return_17 = []() noexcept { return Result(17); };
1401  EXPECT_EQ(17, return_17().x);
1402 
1403  // Just like plain functors, it should work fine to use an AnyInvocable that
1404  // returns the non-moveable type.
1405  using UnqualifiedFun =
1406  absl::conditional_t<TypeParam::kIsNoexcept, Result() noexcept, Result()>;
1407 
1408  using Fun =
1409  GiveQualifiersToFun<typename TypeParam::Qualifiers, UnqualifiedFun>;
1410 
1411  EXPECT_EQ(17, AnyInvocable<Fun>(return_17)().x);
1412 #endif
1413 }
1414 
1415 TYPED_TEST_P(AnyInvTestRvalue, ConversionAssignReferenceWrapper) {
1416  using AnyInvType = typename TypeParam::AnyInvType;
1417  using AddType = typename TypeParam::AddType;
1418 
1419  EXPECT_FALSE((
1420  std::is_assignable<AnyInvType&, std::reference_wrapper<AddType>>::value));
1421 }
1422 
1423 // NOTE: This test suite originally attempted to enumerate all possible
1424 // combinations of type properties but the build-time started getting too large.
1425 // Instead, it is now assumed that certain parameters are orthogonal and so
1426 // some combinations are elided.
1427 
1428 // A metafunction to form a TypeList of all cv and non-rvalue ref combinations,
1429 // coupled with all of the other explicitly specified parameters.
1430 template <Movable Mov, Destructible Dest, NothrowCall CallExceptionSpec,
1431  ObjSize Size, ObjAlign Align>
1432 using NonRvalueQualifiedTestParams = ::testing::Types< //
1433  TestParams<Mov, Dest, _, CallExceptionSpec, Size, Align>, //
1434  TestParams<Mov, Dest, const _, CallExceptionSpec, Size, Align>, //
1435  TestParams<Mov, Dest, _&, CallExceptionSpec, Size, Align>, //
1436  TestParams<Mov, Dest, const _&, CallExceptionSpec, Size, Align>>;
1437 
1438 // A metafunction to form a TypeList of const and non-const rvalue ref
1439 // qualifiers, coupled with all of the other explicitly specified parameters.
1440 template <Movable Mov, Destructible Dest, NothrowCall CallExceptionSpec,
1441  ObjSize Size, ObjAlign Align>
1442 using RvalueQualifiedTestParams = ::testing::Types<
1443  TestParams<Mov, Dest, _&&, CallExceptionSpec, Size, Align>, //
1444  TestParams<Mov, Dest, const _&&, CallExceptionSpec, Size, Align> //
1445  >;
1446 
1447 // All qualifier combinations and a noexcept function type
1448 using TestParameterListNonRvalueQualifiersNothrowCall =
1449  NonRvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1450  NothrowCall::yes, ObjSize::small,
1451  ObjAlign::normal>;
1452 using TestParameterListRvalueQualifiersNothrowCall =
1453  RvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1454  NothrowCall::yes, ObjSize::small,
1455  ObjAlign::normal>;
1456 
1457 // All qualifier combinations and a non-noexcept function type
1458 using TestParameterListNonRvalueQualifiersCallMayThrow =
1459  NonRvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1460  NothrowCall::no, ObjSize::small,
1461  ObjAlign::normal>;
1462 using TestParameterListRvalueQualifiersCallMayThrow =
1463  RvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1464  NothrowCall::no, ObjSize::small,
1465  ObjAlign::normal>;
1466 
1467 // Lists of various cases that should lead to remote storage
1468 using TestParameterListRemoteMovable = ::testing::Types<
1469  // "Normal" aligned types that are large and have trivial destructors
1470  TestParams<Movable::trivial, Destructible::trivial, _, NothrowCall::no,
1471  ObjSize::large, ObjAlign::normal>, //
1472  TestParams<Movable::nothrow, Destructible::trivial, _, NothrowCall::no,
1473  ObjSize::large, ObjAlign::normal>, //
1474  TestParams<Movable::yes, Destructible::trivial, _, NothrowCall::no,
1475  ObjSize::small, ObjAlign::normal>, //
1476  TestParams<Movable::yes, Destructible::trivial, _, NothrowCall::no,
1477  ObjSize::large, ObjAlign::normal>, //
1478 
1479  // Same as above but with non-trivial destructors
1480  TestParams<Movable::trivial, Destructible::nothrow, _, NothrowCall::no,
1481  ObjSize::large, ObjAlign::normal>, //
1482  TestParams<Movable::nothrow, Destructible::nothrow, _, NothrowCall::no,
1483  ObjSize::large, ObjAlign::normal>, //
1484  TestParams<Movable::yes, Destructible::nothrow, _, NothrowCall::no,
1485  ObjSize::small, ObjAlign::normal>, //
1486  TestParams<Movable::yes, Destructible::nothrow, _, NothrowCall::no,
1487  ObjSize::large, ObjAlign::normal> //
1488 
1489 // Dynamic memory allocation for over-aligned data was introduced in C++17.
1490 // See https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0035r4.html
1491 #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
1492  // Types that must use remote storage because of a large alignment.
1493  ,
1494  TestParams<Movable::trivial, Destructible::trivial, _, NothrowCall::no,
1495  ObjSize::small, ObjAlign::large>, //
1496  TestParams<Movable::nothrow, Destructible::trivial, _, NothrowCall::no,
1497  ObjSize::small, ObjAlign::large>, //
1498  TestParams<Movable::trivial, Destructible::nothrow, _, NothrowCall::no,
1499  ObjSize::small, ObjAlign::large>, //
1500  TestParams<Movable::nothrow, Destructible::nothrow, _, NothrowCall::no,
1501  ObjSize::small, ObjAlign::large> //
1502 #endif
1503  >;
1504 using TestParameterListRemoteNonMovable = ::testing::Types<
1505  // "Normal" aligned types that are large and have trivial destructors
1506  TestParams<Movable::no, Destructible::trivial, _, NothrowCall::no,
1507  ObjSize::small, ObjAlign::normal>, //
1508  TestParams<Movable::no, Destructible::trivial, _, NothrowCall::no,
1509  ObjSize::large, ObjAlign::normal>, //
1510  // Same as above but with non-trivial destructors
1511  TestParams<Movable::no, Destructible::nothrow, _, NothrowCall::no,
1512  ObjSize::small, ObjAlign::normal>, //
1513  TestParams<Movable::no, Destructible::nothrow, _, NothrowCall::no,
1514  ObjSize::large, ObjAlign::normal> //
1515  >;
1516 
1517 // Parameters that lead to local storage
1518 using TestParameterListLocal = ::testing::Types<
1519  // Types that meet the requirements and have trivial destructors
1520  TestParams<Movable::trivial, Destructible::trivial, _, NothrowCall::no,
1521  ObjSize::small, ObjAlign::normal>, //
1522  TestParams<Movable::nothrow, Destructible::trivial, _, NothrowCall::no,
1523  ObjSize::small, ObjAlign::normal>, //
1524 
1525  // Same as above but with non-trivial destructors
1526  TestParams<Movable::trivial, Destructible::trivial, _, NothrowCall::no,
1527  ObjSize::small, ObjAlign::normal>, //
1528  TestParams<Movable::nothrow, Destructible::trivial, _, NothrowCall::no,
1529  ObjSize::small, ObjAlign::normal> //
1530  >;
1531 
1532 // All of the tests that are run for every possible combination of types.
1534  AnyInvTestBasic, DefaultConstruction, ConstructionNullptr,
1535  ConstructionNullFunctionPtr, ConstructionNullMemberFunctionPtr,
1536  ConstructionNullMemberObjectPtr, ConstructionMemberFunctionPtr,
1537  ConstructionMemberObjectPtr, ConstructionFunctionReferenceDecay,
1538  ConstructionCompatibleAnyInvocableEmpty,
1539  ConstructionCompatibleAnyInvocableNonempty, InPlaceConstruction,
1540  ConversionToBool, Invocation, InPlaceConstructionInitializerList,
1541  InPlaceNullFunPtrConstruction, InPlaceNullFunPtrConstructionValueInit,
1542  InPlaceNullMemFunPtrConstruction, InPlaceNullMemFunPtrConstructionValueInit,
1543  InPlaceNullMemObjPtrConstruction, InPlaceNullMemObjPtrConstructionValueInit,
1544  InPlaceVoidCovarianceConstruction, MoveConstructionFromEmpty,
1545  MoveConstructionFromNonEmpty, ComparisonWithNullptrEmpty,
1546  ComparisonWithNullptrNonempty, ResultType);
1547 
1549  NonRvalueCallMayThrow, AnyInvTestBasic,
1550  TestParameterListNonRvalueQualifiersCallMayThrow);
1551 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallMayThrow, AnyInvTestBasic,
1552  TestParameterListRvalueQualifiersCallMayThrow);
1553 
1554 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteMovable, AnyInvTestBasic,
1555  TestParameterListRemoteMovable);
1556 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteNonMovable, AnyInvTestBasic,
1557  TestParameterListRemoteNonMovable);
1558 
1559 INSTANTIATE_TYPED_TEST_SUITE_P(Local, AnyInvTestBasic, TestParameterListLocal);
1560 
1561 INSTANTIATE_TYPED_TEST_SUITE_P(NonRvalueCallNothrow, AnyInvTestBasic,
1562  TestParameterListNonRvalueQualifiersNothrowCall);
1563 INSTANTIATE_TYPED_TEST_SUITE_P(CallNothrowRvalue, AnyInvTestBasic,
1564  TestParameterListRvalueQualifiersNothrowCall);
1565 
1566 // Tests for functions that take two operands.
1568  AnyInvTestCombinatoric, MoveAssignEmptyEmptyLhsRhs,
1569  MoveAssignEmptyLhsNonemptyRhs, MoveAssignNonemptyEmptyLhsRhs,
1570  MoveAssignNonemptyLhsNonemptyRhs, SelfMoveAssignEmpty,
1571  SelfMoveAssignNonempty, AssignNullptrEmptyLhs,
1572  AssignNullFunctionPtrEmptyLhs, AssignNullMemberFunctionPtrEmptyLhs,
1573  AssignNullMemberObjectPtrEmptyLhs, AssignMemberFunctionPtrEmptyLhs,
1574  AssignMemberObjectPtrEmptyLhs, AssignFunctionReferenceDecayEmptyLhs,
1575  AssignCompatibleAnyInvocableEmptyLhsEmptyRhs,
1576  AssignCompatibleAnyInvocableEmptyLhsNonemptyRhs, AssignNullptrNonemptyLhs,
1577  AssignNullFunctionPtrNonemptyLhs, AssignNullMemberFunctionPtrNonemptyLhs,
1578  AssignNullMemberObjectPtrNonemptyLhs, AssignMemberFunctionPtrNonemptyLhs,
1579  AssignMemberObjectPtrNonemptyLhs, AssignFunctionReferenceDecayNonemptyLhs,
1580  AssignCompatibleAnyInvocableNonemptyLhsEmptyRhs,
1581  AssignCompatibleAnyInvocableNonemptyLhsNonemptyRhs, SwapEmptyLhsEmptyRhs,
1582  SwapEmptyLhsNonemptyRhs, SwapNonemptyLhsEmptyRhs,
1583  SwapNonemptyLhsNonemptyRhs);
1584 
1586  NonRvalueCallMayThrow, AnyInvTestCombinatoric,
1587  TestParameterListNonRvalueQualifiersCallMayThrow);
1588 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallMayThrow, AnyInvTestCombinatoric,
1589  TestParameterListRvalueQualifiersCallMayThrow);
1590 
1591 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteMovable, AnyInvTestCombinatoric,
1592  TestParameterListRemoteMovable);
1593 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteNonMovable, AnyInvTestCombinatoric,
1594  TestParameterListRemoteNonMovable);
1595 
1596 INSTANTIATE_TYPED_TEST_SUITE_P(Local, AnyInvTestCombinatoric,
1597  TestParameterListLocal);
1598 
1599 INSTANTIATE_TYPED_TEST_SUITE_P(NonRvalueCallNothrow, AnyInvTestCombinatoric,
1600  TestParameterListNonRvalueQualifiersNothrowCall);
1601 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallNothrow, AnyInvTestCombinatoric,
1602  TestParameterListRvalueQualifiersNothrowCall);
1603 
1604 REGISTER_TYPED_TEST_SUITE_P(AnyInvTestMovable,
1605  ConversionConstructionUserDefinedType,
1606  ConversionConstructionVoidCovariance,
1607  ConversionAssignUserDefinedTypeEmptyLhs,
1608  ConversionAssignUserDefinedTypeNonemptyLhs,
1609  ConversionAssignVoidCovariance);
1610 
1612  NonRvalueCallMayThrow, AnyInvTestMovable,
1613  TestParameterListNonRvalueQualifiersCallMayThrow);
1614 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallMayThrow, AnyInvTestMovable,
1615  TestParameterListRvalueQualifiersCallMayThrow);
1616 
1617 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteMovable, AnyInvTestMovable,
1618  TestParameterListRemoteMovable);
1619 
1620 INSTANTIATE_TYPED_TEST_SUITE_P(Local, AnyInvTestMovable,
1621  TestParameterListLocal);
1622 
1623 INSTANTIATE_TYPED_TEST_SUITE_P(NonRvalueCallNothrow, AnyInvTestMovable,
1624  TestParameterListNonRvalueQualifiersNothrowCall);
1625 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallNothrow, AnyInvTestMovable,
1626  TestParameterListRvalueQualifiersNothrowCall);
1627 
1628 REGISTER_TYPED_TEST_SUITE_P(AnyInvTestNoexceptFalse,
1629  ConversionConstructionConstraints,
1630  ConversionAssignConstraints);
1631 
1633  NonRvalueCallMayThrow, AnyInvTestNoexceptFalse,
1634  TestParameterListNonRvalueQualifiersCallMayThrow);
1635 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallMayThrow, AnyInvTestNoexceptFalse,
1636  TestParameterListRvalueQualifiersCallMayThrow);
1637 
1638 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteMovable, AnyInvTestNoexceptFalse,
1639  TestParameterListRemoteMovable);
1640 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteNonMovable, AnyInvTestNoexceptFalse,
1641  TestParameterListRemoteNonMovable);
1642 
1643 INSTANTIATE_TYPED_TEST_SUITE_P(Local, AnyInvTestNoexceptFalse,
1644  TestParameterListLocal);
1645 
1646 REGISTER_TYPED_TEST_SUITE_P(AnyInvTestNoexceptTrue,
1647  ConversionConstructionConstraints,
1648  ConversionAssignConstraints);
1649 
1650 INSTANTIATE_TYPED_TEST_SUITE_P(NonRvalueCallNothrow, AnyInvTestNoexceptTrue,
1651  TestParameterListNonRvalueQualifiersNothrowCall);
1652 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallNothrow, AnyInvTestNoexceptTrue,
1653  TestParameterListRvalueQualifiersNothrowCall);
1654 
1655 REGISTER_TYPED_TEST_SUITE_P(AnyInvTestNonRvalue,
1656  ConversionConstructionReferenceWrapper,
1657  NonMoveableResultType,
1658  ConversionAssignReferenceWrapperEmptyLhs,
1659  ConversionAssignReferenceWrapperNonemptyLhs);
1660 
1662  NonRvalueCallMayThrow, AnyInvTestNonRvalue,
1663  TestParameterListNonRvalueQualifiersCallMayThrow);
1664 
1665 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteMovable, AnyInvTestNonRvalue,
1666  TestParameterListRemoteMovable);
1667 INSTANTIATE_TYPED_TEST_SUITE_P(RemoteNonMovable, AnyInvTestNonRvalue,
1668  TestParameterListRemoteNonMovable);
1669 
1670 INSTANTIATE_TYPED_TEST_SUITE_P(Local, AnyInvTestNonRvalue,
1671  TestParameterListLocal);
1672 
1673 INSTANTIATE_TYPED_TEST_SUITE_P(NonRvalueCallNothrow, AnyInvTestNonRvalue,
1674  TestParameterListNonRvalueQualifiersNothrowCall);
1675 
1676 REGISTER_TYPED_TEST_SUITE_P(AnyInvTestRvalue,
1677  ConversionConstructionReferenceWrapper,
1678  NonMoveableResultType,
1679  ConversionAssignReferenceWrapper);
1680 
1681 INSTANTIATE_TYPED_TEST_SUITE_P(RvalueCallMayThrow, AnyInvTestRvalue,
1682  TestParameterListRvalueQualifiersCallMayThrow);
1683 
1684 INSTANTIATE_TYPED_TEST_SUITE_P(CallNothrowRvalue, AnyInvTestRvalue,
1685  TestParameterListRvalueQualifiersNothrowCall);
1686 
1687 // Minimal SFINAE testing for platforms where we can't run the tests, but we can
1688 // build binaries for.
1689 static_assert(
1690  std::is_convertible<void (*)(), absl::AnyInvocable<void() &&>>::value, "");
1691 static_assert(!std::is_convertible<void*, absl::AnyInvocable<void() &&>>::value,
1692  "");
1693 
1694 #undef ABSL_INTERNAL_NOEXCEPT_SPEC
1695 
1696 } // namespace
TYPED_TEST_P
#define TYPED_TEST_P(SuiteName, TestName)
Definition: googletest/googletest/include/gtest/gtest-typed-test.h:270
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
kSize
static constexpr Tag kSize
Definition: protobuf/src/google/protobuf/descriptor.cc:873
const
#define const
Definition: bloaty/third_party/zlib/zconf.h:230
any_invocable.h
large
int large
Definition: bloaty/third_party/zlib/examples/enough.c:172
google::protobuf.internal::true_type
integral_constant< bool, true > true_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/template_util.h:89
absl::conditional_t
typename std::conditional< B, T, F >::type conditional_t
Definition: abseil-cpp/absl/meta/type_traits.h:634
google::protobuf.internal::false_type
integral_constant< bool, false > false_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/template_util.h:90
absl::internal_any_invocable::kAlignment
@ kAlignment
Definition: internal/any_invocable.h:92
absl::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: abseil-cpp/absl/meta/type_traits.h:631
GTEST_SKIP
#define GTEST_SKIP()
Definition: perf_counters_gtest.cc:10
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
ABSL_INTERNALS_NOARG
#define ABSL_INTERNALS_NOARG
Definition: any_invocable_test.cc:229
T
#define T(upbtypeconst, upbtype, ctype, default_value)
gen_build_yaml.struct
def struct(**kwargs)
Definition: test/core/end2end/gen_build_yaml.py:30
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
testing::internal::ProxyTypeList
Definition: googletest/googletest/include/gtest/internal/gtest-type-util.h:155
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
xds_interop_client.int
int
Definition: xds_interop_client.py:113
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
swap
#define swap(a, b)
Definition: qsort.h:111
re2::Result
TestInstance::Result Result
Definition: bloaty/third_party/re2/re2/testing/tester.cc:96
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
result_type
const typedef int * result_type
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:4325
ABSL_INTERNAL_NOEXCEPT_SPEC
#define ABSL_INTERNAL_NOEXCEPT_SPEC(noex)
Definition: any_invocable_test.cc:39
gmock_output_test._
_
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
ref
unsigned ref
Definition: cxa_demangle.cpp:4909
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:1226
INSTANTIATE_TYPED_TEST_SUITE_P
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types,...)
Definition: googletest/googletest/include/gtest/gtest-typed-test.h:306
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
absl::swap_internal::IsNothrowSwappable
Definition: abseil-cpp/absl/meta/type_traits.h:764
REGISTER_TYPED_TEST_SUITE_P
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName,...)
Definition: googletest/googletest/include/gtest/gtest-typed-test.h:289
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
Json::Int
int Int
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:228
add
static void add(const char *beg, const char *end, char ***ss, size_t *ns)
Definition: debug/trace.cc:96
ABSL_INTERNALS_ADD
#define ABSL_INTERNALS_ADD(qual)
Definition: any_invocable_test.cc:190
value
const char * value
Definition: hpack_parser_table.cc:165
TYPED_TEST_SUITE_P
#define TYPED_TEST_SUITE_P(SuiteName)
Definition: googletest/googletest/include/gtest/gtest-typed-test.h:259
absl::void_t
typename type_traits_internal::VoidTImpl< Ts... >::type void_t
Definition: abseil-cpp/absl/meta/type_traits.h:218
P
Definition: miscompile_with_no_unique_address_test.cc:29
absl::internal_any_invocable::kStorageSize
@ kStorageSize
Definition: internal/any_invocable.h:93
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl::ABSL_NAMESPACE_BEGIN::TestParams
std::vector< TestParam > TestParams
Definition: abseil-cpp/absl/strings/cord_ring_test.cc:95
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
absl::AnyInvocable
Definition: any_invocable.h:152
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
setup.template
template
Definition: setup.py:47
absl::container_internal::internal_layout::adl_barrier::Align
constexpr size_t Align(size_t n, size_t m)
Definition: abseil-cpp/absl/container/internal/layout.h:283
state
static struct rpc_state state
Definition: bad_server_response_test.cc:87


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:41