chromium/third_party/abseil-cpp/absl/meta/type_traits_test.cc

// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "absl/meta/type_traits.h"

#include <cstdint>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include "gtest/gtest.h"
#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"

#ifdef ABSL_HAVE_STD_STRING_VIEW
#include <string_view>
#endif

namespace {

StaticAssertTypeEq;

IsOwnerAndNotView;

static_assert;
static_assert;
static_assert;
#ifdef ABSL_HAVE_STD_STRING_VIEW
static_assert;
static_assert;
#endif

template <class T, class U>
struct simple_pair {};

struct Dummy {};

struct ReturnType {};
struct ConvertibleToReturnType {};

// Unique types used as parameter types for testing the detection idiom.
struct StructA {};
struct StructB {};
struct StructC {};

struct TypeWithBarFunction {};

struct TypeWithBarFunctionAndConvertibleReturnType {};

BarIsCallableImpl;

BarIsCallable;

BarIsCallableConv;

// NOTE: Test of detail type_traits_internal::is_detected.
TEST(IsDetectedTest, BasicUsage) {}

// NOTE: Test of detail type_traits_internal::is_detected_convertible.
TEST(IsDetectedConvertibleTest, BasicUsage) {}

TEST(VoidTTest, BasicUsage) {}

TEST(ConjunctionTest, BasicBooleanLogic) {}

struct MyTrueType {};

struct MyFalseType {};

TEST(ConjunctionTest, ShortCircuiting) {}

TEST(DisjunctionTest, BasicBooleanLogic) {}

TEST(DisjunctionTest, ShortCircuiting) {}

TEST(NegationTest, BasicBooleanLogic) {}

// all member functions are trivial
class Trivial {};

struct TrivialDestructor {};

struct NontrivialDestructor {};

struct DeletedDestructor {};

class TrivialDefaultCtor {};

class NontrivialDefaultCtor {};

class DeletedDefaultCtor {};

class TrivialMoveCtor {};

class NontrivialMoveCtor {};

class TrivialCopyCtor {};

class NontrivialCopyCtor {};

class DeletedCopyCtor {};

class TrivialMoveAssign {};

class NontrivialMoveAssign {};

class TrivialCopyAssign {};

class NontrivialCopyAssign {};

class DeletedCopyAssign {};

struct MovableNonCopyable {};

struct NonCopyableOrMovable {};

class Base {};

TEST(TypeTraitsTest, TestIsFunction) {}

TEST(TypeTraitsTest, TestRemoveCVRef) {}

#define ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(trait_name, ...)

TEST(TypeTraitsTest, TestRemoveCVAliases) {}

TEST(TypeTraitsTest, TestAddCVAliases) {}

TEST(TypeTraitsTest, TestReferenceAliases) {}

TEST(TypeTraitsTest, TestPointerAliases) {}

TEST(TypeTraitsTest, TestSignednessAliases) {}

TEST(TypeTraitsTest, TestExtentAliases) {}

TEST(TypeTraitsTest, TestDecay) {}

struct TypeA {};
struct TypeB {};
struct TypeC {};
struct TypeD {};

template <typename T>
struct Wrap {};

enum class TypeEnum {};

struct GetTypeT {} constexpr GetType =;

TEST(TypeTraitsTest, TestEnableIf) {}

TEST(TypeTraitsTest, TestConditional) {}

// TODO(calabrese) Check with specialized std::common_type
TEST(TypeTraitsTest, TestCommonType) {}

TEST(TypeTraitsTest, TestUnderlyingType) {}

struct GetTypeExtT {} constexpr GetTypeExt =;

TEST(TypeTraitsTest, TestResultOf) {}

namespace adl_namespace {

struct DeletedSwap {};

void swap(DeletedSwap&, DeletedSwap&) = delete;

struct SpecialNoexceptSwap {};

void swap(SpecialNoexceptSwap&, SpecialNoexceptSwap&) noexcept {}

}  // namespace adl_namespace

TEST(TypeTraitsTest, IsSwappable) {}

TEST(TypeTraitsTest, IsNothrowSwappable) {}

TEST(TriviallyRelocatable, PrimitiveTypes) {}

// User-defined types can be trivially relocatable as long as they don't have a
// user-provided move constructor or destructor.
TEST(TriviallyRelocatable, UserDefinedTriviallyRelocatable) {}

// A user-provided move constructor disqualifies a type from being trivially
// relocatable.
TEST(TriviallyRelocatable, UserProvidedMoveConstructor) {}

// A user-provided copy constructor disqualifies a type from being trivially
// relocatable.
TEST(TriviallyRelocatable, UserProvidedCopyConstructor) {}

// A user-provided copy assignment operator disqualifies a type from
// being trivially relocatable.
TEST(TriviallyRelocatable, UserProvidedCopyAssignment) {}

// A user-provided move assignment operator disqualifies a type from
// being trivially relocatable.
TEST(TriviallyRelocatable, UserProvidedMoveAssignment) {}

// A user-provided destructor disqualifies a type from being trivially
// relocatable.
TEST(TriviallyRelocatable, UserProvidedDestructor) {}

// TODO(b/275003464): remove the opt-out for Clang on Windows once
// __is_trivially_relocatable is used there again.
// TODO(b/324278148): remove the opt-out for Apple once
// __is_trivially_relocatable is fixed there.
#if defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) &&      \
    ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && \
    (defined(__cpp_impl_trivially_relocatable) ||    \
     (!defined(__clang__) && !defined(__APPLE__) && !defined(__NVCC__)))
// A type marked with the "trivial ABI" attribute is trivially relocatable even
// if it has user-provided special members.
TEST(TriviallyRelocatable, TrivialAbi) {
  struct ABSL_ATTRIBUTE_TRIVIAL_ABI S {
    S(S&&) {}       // NOLINT(modernize-use-equals-default)
    S(const S&) {}  // NOLINT(modernize-use-equals-default)
    void operator=(S&&) {}
    void operator=(const S&) {}
    ~S() {}  // NOLINT(modernize-use-equals-default)
  };

  static_assert(absl::is_trivially_relocatable<S>::value, "");
}
#endif

#ifdef ABSL_HAVE_CONSTANT_EVALUATED

constexpr int64_t NegateIfConstantEvaluated(int64_t i) {}

#endif  // ABSL_HAVE_CONSTANT_EVALUATED

TEST(IsConstantEvaluated, is_constant_evaluated) {}

}  // namespace