Skip to content

Commit

Permalink
[ADT] Apply fixes from modernize-type-traits (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Apr 16, 2023
1 parent ce47090 commit 9395cf0
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 134 deletions.
10 changes: 5 additions & 5 deletions llvm/include/llvm/ADT/APFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ class APFloat : public APFloatBase {
typedef detail::IEEEFloat IEEEFloat;
typedef detail::DoubleAPFloat DoubleAPFloat;

static_assert(std::is_standard_layout<IEEEFloat>::value);
static_assert(std::is_standard_layout_v<IEEEFloat>);

union Storage {
const fltSemantics *semantics;
Expand Down Expand Up @@ -849,9 +849,9 @@ class APFloat : public APFloatBase {
} U;

template <typename T> static bool usesLayout(const fltSemantics &Semantics) {
static_assert(std::is_same<T, IEEEFloat>::value ||
std::is_same<T, DoubleAPFloat>::value);
if (std::is_same<T, DoubleAPFloat>::value) {
static_assert(std::is_same_v<T, IEEEFloat> ||
std::is_same_v<T, DoubleAPFloat>);
if (std::is_same_v<T, DoubleAPFloat>) {
return &Semantics == &PPCDoubleDouble();
}
return &Semantics != &PPCDoubleDouble();
Expand Down Expand Up @@ -912,7 +912,7 @@ class APFloat : public APFloatBase {
APFloat(const fltSemantics &Semantics, StringRef S);
APFloat(const fltSemantics &Semantics, integerPart I) : U(Semantics, I) {}
template <typename T,
typename = std::enable_if_t<std::is_floating_point<T>::value>>
typename = std::enable_if_t<std::is_floating_point_v<T>>>
APFloat(const fltSemantics &Semantics, T V) = delete;
// TODO: Remove this constructor. This isn't faster than the first one.
APFloat(const fltSemantics &Semantics, uninitializedTag)
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/ADT/Any.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LLVM_EXTERNAL_VISIBILITY Any {
// instead.
template <typename T,
std::enable_if_t<
std::conjunction<
std::conjunction_v<
std::negation<std::is_same<std::decay_t<T>, Any>>,
// We also disable this overload when an `Any` object can be
// converted to the parameter type because in that case,
Expand All @@ -83,7 +83,7 @@ class LLVM_EXTERNAL_VISIBILITY Any {
// adopting it to work-around usage of `Any` with types that
// need to be implicitly convertible from an `Any`.
std::negation<std::is_convertible<Any, std::decay_t<T>>>,
std::is_copy_constructible<std::decay_t<T>>>::value,
std::is_copy_constructible<std::decay_t<T>>>,
int> = 0>
Any(T &&Value) {
Storage =
Expand Down
14 changes: 7 additions & 7 deletions llvm/include/llvm/ADT/ArrayRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ namespace llvm {
/// ensure that only ArrayRefs of pointers can be converted.
template <typename U>
ArrayRef(const ArrayRef<U *> &A,
std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
* = nullptr)
std::enable_if_t<std::is_convertible_v<U *const *, T const *>> * =
nullptr)
: Data(A.data()), Length(A.size()) {}

/// Construct an ArrayRef<const T*> from a SmallVector<T*>. This is
Expand All @@ -132,16 +132,16 @@ namespace llvm {
template <typename U, typename DummyT>
/*implicit*/ ArrayRef(
const SmallVectorTemplateCommon<U *, DummyT> &Vec,
std::enable_if_t<std::is_convertible<U *const *, T const *>::value> * =
std::enable_if_t<std::is_convertible_v<U *const *, T const *>> * =
nullptr)
: Data(Vec.data()), Length(Vec.size()) {}

/// Construct an ArrayRef<const T*> from std::vector<T*>. This uses SFINAE
/// to ensure that only vectors of pointers can be converted.
template <typename U, typename A>
ArrayRef(const std::vector<U *, A> &Vec,
std::enable_if_t<std::is_convertible<U *const *, T const *>::value>
* = nullptr)
std::enable_if_t<std::is_convertible_v<U *const *, T const *>> * =
nullptr)
: Data(Vec.data()), Length(Vec.size()) {}

/// @}
Expand Down Expand Up @@ -261,15 +261,15 @@ namespace llvm {
/// The declaration here is extra complicated so that "arrayRef = {}"
/// continues to select the move assignment operator.
template <typename U>
std::enable_if_t<std::is_same<U, T>::value, ArrayRef<T>> &
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>> &
operator=(U &&Temporary) = delete;

/// Disallow accidental assignment from a temporary.
///
/// The declaration here is extra complicated so that "arrayRef = {}"
/// continues to select the move assignment operator.
template <typename U>
std::enable_if_t<std::is_same<U, T>::value, ArrayRef<T>> &
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>> &
operator=(std::initializer_list<U>) = delete;

/// @}
Expand Down
21 changes: 9 additions & 12 deletions llvm/include/llvm/ADT/Bitfields.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ template <typename T, unsigned Bits> struct BitPatterns {
/// type so it can be packed and unpacked into a `bits` sized integer,
/// `Compressor` is specialized on signed-ness so no runtime cost is incurred.
/// The `pack` method also checks that the passed in `UserValue` is valid.
template <typename T, unsigned Bits, bool = std::is_unsigned<T>::value>
template <typename T, unsigned Bits, bool = std::is_unsigned_v<T>>
struct Compressor {
static_assert(std::is_unsigned<T>::value, "T must be unsigned");
static_assert(std::is_unsigned_v<T>, "T must be unsigned");
using BP = BitPatterns<T, Bits>;

static T pack(T UserValue, T UserMaxValue) {
Expand All @@ -132,7 +132,7 @@ struct Compressor {
};

template <typename T, unsigned Bits> struct Compressor<T, Bits, false> {
static_assert(std::is_signed<T>::value, "T must be signed");
static_assert(std::is_signed_v<T>, "T must be signed");
using BP = BitPatterns<T, Bits>;

static T pack(T UserValue, T UserMaxValue) {
Expand All @@ -154,8 +154,7 @@ template <typename T, unsigned Bits> struct Compressor<T, Bits, false> {
/// Impl is where Bifield description and Storage are put together to interact
/// with values.
template <typename Bitfield, typename StorageType> struct Impl {
static_assert(std::is_unsigned<StorageType>::value,
"Storage must be unsigned");
static_assert(std::is_unsigned_v<StorageType>, "Storage must be unsigned");
using IntegerType = typename Bitfield::IntegerType;
using C = Compressor<IntegerType, Bitfield::Bits>;
using BP = BitPatterns<StorageType, Bitfield::Bits>;
Expand Down Expand Up @@ -193,8 +192,7 @@ template <typename Bitfield, typename StorageType> struct Impl {
/// consistent semantics, this excludes typed enums and `bool` that are replaced
/// with their unsigned counterparts. The correct type is restored in the public
/// API.
template <typename T, bool = std::is_enum<T>::value>
struct ResolveUnderlyingType {
template <typename T, bool = std::is_enum_v<T>> struct ResolveUnderlyingType {
using type = std::underlying_type_t<T>;
};
template <typename T> struct ResolveUnderlyingType<T, false> {
Expand All @@ -217,7 +215,7 @@ struct Bitfield {
/// \tparam Size The size of the field.
/// \tparam MaxValue For enums the maximum enum allowed.
template <typename T, unsigned Offset, unsigned Size,
T MaxValue = std::is_enum<T>::value
T MaxValue = std::is_enum_v<T>
? T(0) // coupled with static_assert below
: std::numeric_limits<T>::max()>
struct Element {
Expand All @@ -236,12 +234,11 @@ struct Bitfield {
static_assert(Bits > 0, "Bits must be non zero");
static constexpr size_t TypeBits = sizeof(IntegerType) * CHAR_BIT;
static_assert(Bits <= TypeBits, "Bits may not be greater than T size");
static_assert(!std::is_enum<T>::value || MaxValue != T(0),
static_assert(!std::is_enum_v<T> || MaxValue != T(0),
"Enum Bitfields must provide a MaxValue");
static_assert(!std::is_enum<T>::value ||
std::is_unsigned<IntegerType>::value,
static_assert(!std::is_enum_v<T> || std::is_unsigned_v<IntegerType>,
"Enum must be unsigned");
static_assert(std::is_integral<IntegerType>::value &&
static_assert(std::is_integral_v<IntegerType> &&
std::numeric_limits<IntegerType>::is_integer,
"IntegerType must be an integer type");

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/CoalescingBitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace llvm {
///
/// \tparam IndexT - The type of the index into the bitvector.
template <typename IndexT> class CoalescingBitVector {
static_assert(std::is_unsigned<IndexT>::value,
static_assert(std::is_unsigned_v<IndexT>,
"Index must be an unsigned integer.");

using ThisT = CoalescingBitVector<IndexT>;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class DenseMapBase : public DebugEpochBase {
}

static const KeyT getEmptyKey() {
static_assert(std::is_base_of<DenseMapBase, DerivedT>::value,
static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
"Must pass the derived type to this template!");
return KeyInfoT::getEmptyKey();
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/FoldingSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ struct FoldingSetTrait<std::pair<T1, T2>> {
};

template <typename T>
struct FoldingSetTrait<T, std::enable_if_t<std::is_enum<T>::value>> {
struct FoldingSetTrait<T, std::enable_if_t<std::is_enum_v<T>>> {
static void Profile(const T &X, FoldingSetNodeID &ID) {
ID.AddInteger(static_cast<std::underlying_type_t<T>>(X));
}
Expand Down
13 changes: 6 additions & 7 deletions llvm/include/llvm/ADT/FunctionExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,20 @@ namespace detail {
template <typename T>
using EnableIfTrivial =
std::enable_if_t<llvm::is_trivially_move_constructible<T>::value &&
std::is_trivially_destructible<T>::value>;
std::is_trivially_destructible_v<T>>;
template <typename CallableT, typename ThisT>
using EnableUnlessSameType =
std::enable_if_t<!std::is_same<remove_cvref_t<CallableT>, ThisT>::value>;
std::enable_if_t<!std::is_same_v<remove_cvref_t<CallableT>, ThisT>>;
template <typename CallableT, typename Ret, typename... Params>
using EnableIfCallable = std::enable_if_t<std::disjunction<
using EnableIfCallable = std::enable_if_t<std::disjunction_v<
std::is_void<Ret>,
std::is_same<decltype(std::declval<CallableT>()(std::declval<Params>()...)),
Ret>,
std::is_same<const decltype(std::declval<CallableT>()(
std::declval<Params>()...)),
Ret>,
std::is_convertible<decltype(std::declval<CallableT>()(
std::declval<Params>()...)),
Ret>>::value>;
std::is_convertible<
decltype(std::declval<CallableT>()(std::declval<Params>()...)), Ret>>>;

template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
protected:
Expand All @@ -97,7 +96,7 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
// It doesn't have to be exact though, and in one way it is more strict
// because we want to still be able to observe either moves *or* copies.
template <typename T> struct AdjustedParamTBase {
static_assert(!std::is_reference<T>::value,
static_assert(!std::is_reference_v<T>,
"references should be handled by template specialization");
using type = std::conditional_t<
llvm::is_trivially_copy_constructible<T>::value &&
Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/ADT/Hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,12 @@ inline uint64_t get_execution_seed() {
// for equality. For all the platforms we care about, this holds for integers
// and pointers, but there are platforms where it doesn't and we would like to
// support user-defined types which happen to satisfy this property.
template <typename T> struct is_hashable_data
: std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
std::is_pointer<T>::value) &&
64 % sizeof(T) == 0)> {};
template <typename T>
struct is_hashable_data
: std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
std::is_pointer_v<T>)&&64 %
sizeof(T) ==
0)> {};

// Special case std::pair to detect when both types are viable and when there
// is no alignment-derived padding in the pair. This is a bit of a lie because
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ template <typename T> class IntrusiveRefCntPtr {
IntrusiveRefCntPtr(IntrusiveRefCntPtr &&S) : Obj(S.Obj) { S.Obj = nullptr; }

template <class X,
std::enable_if_t<std::is_convertible<X *, T *>::value, bool> = true>
std::enable_if_t<std::is_convertible_v<X *, T *>, bool> = true>
IntrusiveRefCntPtr(IntrusiveRefCntPtr<X> S) : Obj(S.get()) {
S.Obj = nullptr;
}

template <class X,
std::enable_if_t<std::is_convertible<X *, T *>::value, bool> = true>
std::enable_if_t<std::is_convertible_v<X *, T *>, bool> = true>
IntrusiveRefCntPtr(std::unique_ptr<X> S) : Obj(S.release()) {
retain();
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/ADT/PointerIntPair.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ template <typename Ptr> struct PunnedPointer {

// Asserts that allow us to let the compiler implement the destructor and
// copy/move constructors
static_assert(std::is_trivially_destructible<Ptr>::value, "");
static_assert(std::is_trivially_copy_constructible<Ptr>::value, "");
static_assert(std::is_trivially_move_constructible<Ptr>::value, "");
static_assert(std::is_trivially_destructible_v<Ptr>, "");
static_assert(std::is_trivially_copy_constructible_v<Ptr>, "");
static_assert(std::is_trivially_move_constructible_v<Ptr>, "");

explicit constexpr PunnedPointer(intptr_t i = 0) { *this = i; }

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ADT/PriorityWorklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PriorityWorklist {

/// Insert a sequence of new elements into the PriorityWorklist.
template <typename SequenceT>
std::enable_if_t<!std::is_convertible<SequenceT, T>::value>
std::enable_if_t<!std::is_convertible_v<SequenceT, T>>
insert(SequenceT &&Input) {
if (std::begin(Input) == std::end(Input))
// Nothing to do for an empty input sequence.
Expand Down
Loading

0 comments on commit 9395cf0

Please sign in to comment.