tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

any_invocable_test.cc (60541B)


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