[llvm] a7428bb - [Support] Apply fixes from modernize-type-trait (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 16 19:20:32 PDT 2023
Author: Kazu Hirata
Date: 2023-04-16T19:20:21-07:00
New Revision: a7428bbb6bdb79a15e567a34d4dcc9775454ed71
URL: https://github.com/llvm/llvm-project/commit/a7428bbb6bdb79a15e567a34d4dcc9775454ed71
DIFF: https://github.com/llvm/llvm-project/commit/a7428bbb6bdb79a15e567a34d4dcc9775454ed71.diff
LOG: [Support] Apply fixes from modernize-type-trait (NFC)
Added:
Modified:
llvm/include/llvm/Support/Alignment.h
llvm/include/llvm/Support/AllocatorBase.h
llvm/include/llvm/Support/Casting.h
llvm/include/llvm/Support/CheckedArithmetic.h
llvm/include/llvm/Support/CommandLine.h
llvm/include/llvm/Support/Error.h
llvm/include/llvm/Support/ErrorOr.h
llvm/include/llvm/Support/FormatProviders.h
llvm/include/llvm/Support/FormatVariadicDetails.h
llvm/include/llvm/Support/GenericDomTree.h
llvm/include/llvm/Support/GraphWriter.h
llvm/include/llvm/Support/JSON.h
llvm/include/llvm/Support/MathExtras.h
llvm/include/llvm/Support/SwapByteOrder.h
llvm/include/llvm/Support/TrailingObjects.h
llvm/include/llvm/Support/TypeSize.h
llvm/include/llvm/Support/YAMLTraits.h
llvm/include/llvm/Support/raw_ostream.h
llvm/include/llvm/Support/type_traits.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Alignment.h b/llvm/include/llvm/Support/Alignment.h
index 4577641818be3..8d4a7e7ddce5f 100644
--- a/llvm/include/llvm/Support/Alignment.h
+++ b/llvm/include/llvm/Support/Alignment.h
@@ -100,7 +100,7 @@ struct Align {
/// Allow constructions of constexpr Align from types.
/// Compile time equivalent to Align(alignof(T)).
template <typename T> constexpr static Align Of() {
- return Constant<std::alignment_of<T>::value>();
+ return Constant<std::alignment_of_v<T>>();
}
/// Constexpr constructor from LogValue type.
diff --git a/llvm/include/llvm/Support/AllocatorBase.h b/llvm/include/llvm/Support/AllocatorBase.h
index 5d05d3f8777b0..278ec434d384c 100644
--- a/llvm/include/llvm/Support/AllocatorBase.h
+++ b/llvm/include/llvm/Support/AllocatorBase.h
@@ -72,7 +72,7 @@ template <typename DerivedT> class AllocatorBase {
/// Deallocate space for a sequence of objects without constructing them.
template <typename T>
- std::enable_if_t<!std::is_same<std::remove_cv_t<T>, void>::value, void>
+ std::enable_if_t<!std::is_same_v<std::remove_cv_t<T>, void>, void>
Deallocate(T *Ptr, size_t Num = 1) {
Deallocate(static_cast<const void *>(Ptr), Num * sizeof(T), alignof(T));
}
diff --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 4ff5865185d75..a0a6fb053d314 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -66,7 +66,7 @@ template <typename To, typename From, typename Enabler = void> struct isa_impl {
// Always allow upcasts, and perform no dynamic check for them.
template <typename To, typename From>
-struct isa_impl<To, From, std::enable_if_t<std::is_base_of<To, From>::value>> {
+struct isa_impl<To, From, std::enable_if_t<std::is_base_of_v<To, From>>> {
static inline bool doit(const From &) { return true; }
};
@@ -231,7 +231,7 @@ struct cast_convert_val<To, FromTy *, FromTy *> {
template <class X> struct is_simple_type {
static const bool value =
- std::is_same<X, typename simplify_type<X>::SimpleType>::value;
+ std::is_same_v<X, typename simplify_type<X>::SimpleType>;
};
// } // namespace detail
@@ -275,8 +275,7 @@ struct CastIsPossible<To, std::optional<From>> {
/// Upcasting (from derived to base) and casting from a type to itself should
/// always be possible.
template <typename To, typename From>
-struct CastIsPossible<To, From,
- std::enable_if_t<std::is_base_of<To, From>::value>> {
+struct CastIsPossible<To, From, std::enable_if_t<std::is_base_of_v<To, From>>> {
static inline bool isPossible(const From &f) { return true; }
};
@@ -319,7 +318,7 @@ namespace detail {
/// A helper to derive the type to use with `Self` for cast traits, when the
/// provided CRTP derived type is allowed to be void.
template <typename OptionalDerived, typename Default>
-using SelfType = std::conditional_t<std::is_same<OptionalDerived, void>::value,
+using SelfType = std::conditional_t<std::is_same_v<OptionalDerived, void>,
Default, OptionalDerived>;
} // namespace detail
@@ -390,8 +389,8 @@ struct ConstStrippingForwardingCast {
// Remove the pointer if it exists, then we can get rid of consts/volatiles.
using DecayedFrom = std::remove_cv_t<std::remove_pointer_t<From>>;
// Now if it's a pointer, add it back. Otherwise, we want a ref.
- using NonConstFrom = std::conditional_t<std::is_pointer<From>::value,
- DecayedFrom *, DecayedFrom &>;
+ using NonConstFrom =
+ std::conditional_t<std::is_pointer_v<From>, DecayedFrom *, DecayedFrom &>;
static inline bool isPossible(const From &f) {
return ForwardTo::isPossible(const_cast<NonConstFrom>(f));
diff --git a/llvm/include/llvm/Support/CheckedArithmetic.h b/llvm/include/llvm/Support/CheckedArithmetic.h
index 81b703a038921..69dcdc74e0153 100644
--- a/llvm/include/llvm/Support/CheckedArithmetic.h
+++ b/llvm/include/llvm/Support/CheckedArithmetic.h
@@ -25,8 +25,7 @@ namespace {
/// \p RHS.
/// \return Empty optional if the operation overflows, or result otherwise.
template <typename T, typename F>
-std::enable_if_t<std::is_integral<T>::value && sizeof(T) * 8 <= 64,
- std::optional<T>>
+std::enable_if_t<std::is_integral_v<T> && sizeof(T) * 8 <= 64, std::optional<T>>
checkedOp(T LHS, T RHS, F Op, bool Signed = true) {
llvm::APInt ALHS(sizeof(T) * 8, LHS, Signed);
llvm::APInt ARHS(sizeof(T) * 8, RHS, Signed);
@@ -44,8 +43,8 @@ namespace llvm {
/// \return Optional of sum if no signed overflow occurred,
/// \c std::nullopt otherwise.
template <typename T>
-std::enable_if_t<std::is_signed<T>::value, std::optional<T>>
-checkedAdd(T LHS, T RHS) {
+std::enable_if_t<std::is_signed_v<T>, std::optional<T>> checkedAdd(T LHS,
+ T RHS) {
return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov);
}
@@ -53,8 +52,8 @@ checkedAdd(T LHS, T RHS) {
/// \return Optional of sum if no signed overflow occurred,
/// \c std::nullopt otherwise.
template <typename T>
-std::enable_if_t<std::is_signed<T>::value, std::optional<T>>
-checkedSub(T LHS, T RHS) {
+std::enable_if_t<std::is_signed_v<T>, std::optional<T>> checkedSub(T LHS,
+ T RHS) {
return checkedOp(LHS, RHS, &llvm::APInt::ssub_ov);
}
@@ -62,8 +61,8 @@ checkedSub(T LHS, T RHS) {
/// \return Optional of product if no signed overflow occurred,
/// \c std::nullopt otherwise.
template <typename T>
-std::enable_if_t<std::is_signed<T>::value, std::optional<T>>
-checkedMul(T LHS, T RHS) {
+std::enable_if_t<std::is_signed_v<T>, std::optional<T>> checkedMul(T LHS,
+ T RHS) {
return checkedOp(LHS, RHS, &llvm::APInt::smul_ov);
}
@@ -71,8 +70,8 @@ checkedMul(T LHS, T RHS) {
/// \return Optional of result if no signed overflow occurred,
/// \c std::nullopt otherwise.
template <typename T>
-std::enable_if_t<std::is_signed<T>::value, std::optional<T>>
-checkedMulAdd(T A, T B, T C) {
+std::enable_if_t<std::is_signed_v<T>, std::optional<T>> checkedMulAdd(T A, T B,
+ T C) {
if (auto Product = checkedMul(A, B))
return checkedAdd(*Product, C);
return std::nullopt;
@@ -82,7 +81,7 @@ checkedMulAdd(T A, T B, T C) {
/// \return Optional of sum if no unsigned overflow occurred,
/// \c std::nullopt otherwise.
template <typename T>
-std::enable_if_t<std::is_unsigned<T>::value, std::optional<T>>
+std::enable_if_t<std::is_unsigned_v<T>, std::optional<T>>
checkedAddUnsigned(T LHS, T RHS) {
return checkedOp(LHS, RHS, &llvm::APInt::uadd_ov, /*Signed=*/false);
}
@@ -91,7 +90,7 @@ checkedAddUnsigned(T LHS, T RHS) {
/// \return Optional of product if no unsigned overflow occurred,
/// \c std::nullopt otherwise.
template <typename T>
-std::enable_if_t<std::is_unsigned<T>::value, std::optional<T>>
+std::enable_if_t<std::is_unsigned_v<T>, std::optional<T>>
checkedMulUnsigned(T LHS, T RHS) {
return checkedOp(LHS, RHS, &llvm::APInt::umul_ov, /*Signed=*/false);
}
@@ -100,7 +99,7 @@ checkedMulUnsigned(T LHS, T RHS) {
/// \return Optional of result if no unsigned overflow occurred,
/// \c std::nullopt otherwise.
template <typename T>
-std::enable_if_t<std::is_unsigned<T>::value, std::optional<T>>
+std::enable_if_t<std::is_unsigned_v<T>, std::optional<T>>
checkedMulAddUnsigned(T A, T B, T C) {
if (auto Product = checkedMulUnsigned(A, B))
return checkedAddUnsigned(*Product, C);
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 04737efecb2b8..d2079fead6680 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -503,10 +503,10 @@ struct callback_traits<R (C::*)(Args...) const> {
using result_type = R;
using arg_type = std::tuple_element_t<0, std::tuple<Args...>>;
static_assert(sizeof...(Args) == 1, "callback function must have one and only one parameter");
- static_assert(std::is_same<result_type, void>::value,
+ static_assert(std::is_same_v<result_type, void>,
"callback return type must be void");
- static_assert(std::is_lvalue_reference<arg_type>::value &&
- std::is_const<std::remove_reference_t<arg_type>>::value,
+ static_assert(std::is_lvalue_reference_v<arg_type> &&
+ std::is_const_v<std::remove_reference_t<arg_type>>,
"callback arg_type must be a const lvalue reference");
};
} // namespace detail
@@ -613,7 +613,7 @@ struct OptionValueBase<DataType, false> : OptionValueCopy<DataType> {
// Top-level option class.
template <class DataType>
struct OptionValue final
- : OptionValueBase<DataType, std::is_class<DataType>::value> {
+ : OptionValueBase<DataType, std::is_class_v<DataType>> {
OptionValue() = default;
OptionValue(const DataType &V) { this->setValue(V); }
@@ -1407,9 +1407,9 @@ template <class DataType> class opt_storage<DataType, false, false> {
//
template <class DataType, bool ExternalStorage = false,
class ParserClass = parser<DataType>>
-class opt : public Option,
- public opt_storage<DataType, ExternalStorage,
- std::is_class<DataType>::value> {
+class opt
+ : public Option,
+ public opt_storage<DataType, ExternalStorage, std::is_class_v<DataType>> {
ParserClass Parser;
bool handleOccurrence(unsigned pos, StringRef ArgName,
@@ -1448,8 +1448,7 @@ class opt : public Option,
}
}
- template <class T,
- class = std::enable_if_t<std::is_assignable<T &, T>::value>>
+ template <class T, class = std::enable_if_t<std::is_assignable_v<T &, T>>>
void setDefaultImpl() {
const OptionValue<DataType> &V = this->getDefault();
if (V.hasValue())
@@ -1458,8 +1457,7 @@ class opt : public Option,
this->setValue(T());
}
- template <class T,
- class = std::enable_if_t<!std::is_assignable<T &, T>::value>>
+ template <class T, class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
void setDefaultImpl(...) {}
void setDefault() override { setDefaultImpl<DataType>(); }
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 8a984db5e681c..0f1b6321762d0 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -471,7 +471,7 @@ template <class T> class [[nodiscard]] Expected {
template <class T1> friend class ExpectedAsOutParameter;
template <class OtherT> friend class Expected;
- static constexpr bool isRef = std::is_reference<T>::value;
+ static constexpr bool isRef = std::is_reference_v<T>;
using wrap = std::reference_wrapper<std::remove_reference_t<T>>;
@@ -577,9 +577,9 @@ template <class T> class [[nodiscard]] Expected {
/// Returns \a takeError() after moving the held T (if any) into \p V.
template <class OtherT>
- Error moveInto(OtherT &Value,
- std::enable_if_t<std::is_assignable<OtherT &, T &&>::value> * =
- nullptr) && {
+ Error moveInto(
+ OtherT &Value,
+ std::enable_if_t<std::is_assignable_v<OtherT &, T &&>> * = nullptr) && {
if (*this)
Value = std::move(get());
return takeError();
diff --git a/llvm/include/llvm/Support/ErrorOr.h b/llvm/include/llvm/Support/ErrorOr.h
index b654c9c9c43be..97c7abe1f20c5 100644
--- a/llvm/include/llvm/Support/ErrorOr.h
+++ b/llvm/include/llvm/Support/ErrorOr.h
@@ -56,7 +56,7 @@ template<class T>
class ErrorOr {
template <class OtherT> friend class ErrorOr;
- static constexpr bool isRef = std::is_reference<T>::value;
+ static constexpr bool isRef = std::is_reference_v<T>;
using wrap = std::reference_wrapper<std::remove_reference_t<T>>;
@@ -85,7 +85,7 @@ class ErrorOr {
template <class OtherT>
ErrorOr(OtherT &&Val,
- std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr)
+ std::enable_if_t<std::is_convertible_v<OtherT, T>> * = nullptr)
: HasError(false) {
new (getStorage()) storage_type(std::forward<OtherT>(Val));
}
@@ -96,15 +96,14 @@ class ErrorOr {
template <class OtherT>
ErrorOr(const ErrorOr<OtherT> &Other,
- std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr) {
+ std::enable_if_t<std::is_convertible_v<OtherT, T>> * = nullptr) {
copyConstruct(Other);
}
template <class OtherT>
explicit ErrorOr(
const ErrorOr<OtherT> &Other,
- std::enable_if_t<!std::is_convertible<OtherT, const T &>::value> * =
- nullptr) {
+ std::enable_if_t<!std::is_convertible_v<OtherT, const T &>> * = nullptr) {
copyConstruct(Other);
}
@@ -114,7 +113,7 @@ class ErrorOr {
template <class OtherT>
ErrorOr(ErrorOr<OtherT> &&Other,
- std::enable_if_t<std::is_convertible<OtherT, T>::value> * = nullptr) {
+ std::enable_if_t<std::is_convertible_v<OtherT, T>> * = nullptr) {
moveConstruct(std::move(Other));
}
@@ -123,7 +122,7 @@ class ErrorOr {
template <class OtherT>
explicit ErrorOr(
ErrorOr<OtherT> &&Other,
- std::enable_if_t<!std::is_convertible<OtherT, T>::value> * = nullptr) {
+ std::enable_if_t<!std::is_convertible_v<OtherT, T>> * = nullptr) {
moveConstruct(std::move(Other));
}
diff --git a/llvm/include/llvm/Support/FormatProviders.h b/llvm/include/llvm/Support/FormatProviders.h
index 44da741b456e9..bc227e99dfbee 100644
--- a/llvm/include/llvm/Support/FormatProviders.h
+++ b/llvm/include/llvm/Support/FormatProviders.h
@@ -35,7 +35,7 @@ struct use_integral_formatter
template <typename T>
struct use_char_formatter
- : public std::integral_constant<bool, std::is_same<T, char>::value> {};
+ : public std::integral_constant<bool, std::is_same_v<T, char>> {};
template <typename T>
struct is_cstring
@@ -46,16 +46,17 @@ struct is_cstring
template <typename T>
struct use_string_formatter
: public std::integral_constant<bool,
- std::is_convertible<T, llvm::StringRef>::value> {};
+ std::is_convertible_v<T, llvm::StringRef>> {
+};
template <typename T>
struct use_pointer_formatter
- : public std::integral_constant<bool, std::is_pointer<T>::value &&
+ : public std::integral_constant<bool, std::is_pointer_v<T> &&
!is_cstring<T>::value> {};
template <typename T>
struct use_double_formatter
- : public std::integral_constant<bool, std::is_floating_point<T>::value> {};
+ : public std::integral_constant<bool, std::is_floating_point_v<T>> {};
class HelperFunctions {
protected:
diff --git a/llvm/include/llvm/Support/FormatVariadicDetails.h b/llvm/include/llvm/Support/FormatVariadicDetails.h
index 2204cff13a64d..068c327df3967 100644
--- a/llvm/include/llvm/Support/FormatVariadicDetails.h
+++ b/llvm/include/llvm/Support/FormatVariadicDetails.h
@@ -79,11 +79,11 @@ template <class T> class has_StreamOperator {
using ConstRefT = const std::decay_t<T> &;
template <typename U>
- static char test(
- std::enable_if_t<std::is_same<decltype(std::declval<llvm::raw_ostream &>()
- << std::declval<U>()),
- llvm::raw_ostream &>::value,
- int *>);
+ static char test(std::enable_if_t<
+ std::is_same_v<decltype(std::declval<llvm::raw_ostream &>()
+ << std::declval<U>()),
+ llvm::raw_ostream &>,
+ int *>);
template <typename U> static double test(...);
@@ -95,8 +95,7 @@ template <class T> class has_StreamOperator {
template <typename T>
struct uses_format_member
: public std::integral_constant<
- bool,
- std::is_base_of<format_adapter, std::remove_reference_t<T>>::value> {
+ bool, std::is_base_of_v<format_adapter, std::remove_reference_t<T>>> {
};
// Simple template that decides whether a type T should use the format_provider
@@ -147,7 +146,7 @@ build_format_adapter(T &&Item) {
// would be responsible for consuming it.
// Make the caller opt into this by calling fmt_consume().
static_assert(
- !std::is_same<llvm::Error, std::remove_cv_t<T>>::value,
+ !std::is_same_v<llvm::Error, std::remove_cv_t<T>>,
"llvm::Error-by-value must be wrapped in fmt_consume() for formatv");
return stream_operator_format_adapter<T>(std::forward<T>(Item));
}
diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h
index 1e5c0ae231d27..62186a368e964 100644
--- a/llvm/include/llvm/Support/GenericDomTree.h
+++ b/llvm/include/llvm/Support/GenericDomTree.h
@@ -227,7 +227,7 @@ template <typename NodeT> struct DomTreeNodeTraits {
using NodeType = NodeT;
using NodePtr = NodeT *;
using ParentPtr = decltype(std::declval<NodePtr>()->getParent());
- static_assert(std::is_pointer<ParentPtr>::value,
+ static_assert(std::is_pointer_v<ParentPtr>,
"Currently NodeT's parent must be a pointer type");
using ParentType = std::remove_pointer_t<ParentPtr>;
@@ -242,13 +242,13 @@ template <typename NodeT> struct DomTreeNodeTraits {
template <typename NodeT, bool IsPostDom>
class DominatorTreeBase {
public:
- static_assert(std::is_pointer<typename GraphTraits<NodeT *>::NodeRef>::value,
+ static_assert(std::is_pointer_v<typename GraphTraits<NodeT *>::NodeRef>,
"Currently DominatorTreeBase supports only pointer nodes");
using NodeTrait = DomTreeNodeTraits<NodeT>;
using NodeType = typename NodeTrait::NodeType;
using NodePtr = typename NodeTrait::NodePtr;
using ParentPtr = typename NodeTrait::ParentPtr;
- static_assert(std::is_pointer<ParentPtr>::value,
+ static_assert(std::is_pointer_v<ParentPtr>,
"Currently NodeT's parent must be a pointer type");
using ParentType = std::remove_pointer_t<ParentPtr>;
static constexpr bool IsPostDominator = IsPostDom;
diff --git a/llvm/include/llvm/Support/GraphWriter.h b/llvm/include/llvm/Support/GraphWriter.h
index 515057e7e312f..dfda605365de3 100644
--- a/llvm/include/llvm/Support/GraphWriter.h
+++ b/llvm/include/llvm/Support/GraphWriter.h
@@ -73,7 +73,7 @@ class GraphWriter {
using child_iterator = typename GTraits::ChildIteratorType;
DOTTraits DTraits;
- static_assert(std::is_pointer<NodeRef>::value,
+ static_assert(std::is_pointer_v<NodeRef>,
"FIXME: Currently GraphWriter requires the NodeRef type to be "
"a pointer.\nThe pointer usage should be moved to "
"DOTGraphTraits, and removed from GraphWriter itself.");
diff --git a/llvm/include/llvm/Support/JSON.h b/llvm/include/llvm/Support/JSON.h
index 2c97cde059f91..a81881c52d6c9 100644
--- a/llvm/include/llvm/Support/JSON.h
+++ b/llvm/include/llvm/Support/JSON.h
@@ -334,8 +334,7 @@ class Value {
Value(std::nullptr_t) : Type(T_Null) {}
// Boolean (disallow implicit conversions).
// (The last template parameter is a dummy to keep templates distinct.)
- template <typename T,
- typename = std::enable_if_t<std::is_same<T, bool>::value>,
+ template <typename T, typename = std::enable_if_t<std::is_same_v<T, bool>>,
bool = false>
Value(T B) : Type(T_Boolean) {
create<bool>(B);
@@ -357,15 +356,15 @@ class Value {
}
// Floating point. Must be non-narrowing convertible to double.
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>>,
double * = nullptr>
Value(T D) : Type(T_Double) {
create<double>(double{D});
}
// Serializable types: with a toJSON(const T&)->Value function, found by ADL.
template <typename T,
- typename = std::enable_if_t<std::is_same<
- Value, decltype(toJSON(*(const T *)nullptr))>::value>,
+ typename = std::enable_if_t<
+ std::is_same_v<Value, decltype(toJSON(*(const T *)nullptr))>>,
Value * = nullptr>
Value(const T &V) : Value(toJSON(V)) {}
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 92f5b4562be97..54e8a4fbb5fe9 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -91,7 +91,7 @@ unsigned countLeadingZeros(T Val) {
/// Create a bitmask with the N right-most bits set to 1, and all other
/// bits set to 0. Only unsigned types are allowed.
template <typename T> T maskTrailingOnes(unsigned N) {
- static_assert(std::is_unsigned<T>::value, "Invalid type!");
+ static_assert(std::is_unsigned_v<T>, "Invalid type!");
const unsigned Bits = CHAR_BIT * sizeof(T);
assert(N <= Bits && "Invalid bit index");
return N == 0 ? 0 : (T(-1) >> (Bits - N));
@@ -571,7 +571,7 @@ inline int64_t SignExtend64(uint64_t X, unsigned B) {
/// Subtract two unsigned integers, X and Y, of type T and return the absolute
/// value of the result.
template <typename T>
-std::enable_if_t<std::is_unsigned<T>::value, T> AbsoluteDifference(T X, T Y) {
+std::enable_if_t<std::is_unsigned_v<T>, T> AbsoluteDifference(T X, T Y) {
return X > Y ? (X - Y) : (Y - X);
}
@@ -579,7 +579,7 @@ std::enable_if_t<std::is_unsigned<T>::value, T> AbsoluteDifference(T X, T Y) {
/// maximum representable value of T on overflow. ResultOverflowed indicates if
/// the result is larger than the maximum representable value of type T.
template <typename T>
-std::enable_if_t<std::is_unsigned<T>::value, T>
+std::enable_if_t<std::is_unsigned_v<T>, T>
SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
bool Dummy;
bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
@@ -608,7 +608,7 @@ std::enable_if_t<std::is_unsigned_v<T>, T> SaturatingAdd(T X, T Y, T Z,
/// maximum representable value of T on overflow. ResultOverflowed indicates if
/// the result is larger than the maximum representable value of type T.
template <typename T>
-std::enable_if_t<std::is_unsigned<T>::value, T>
+std::enable_if_t<std::is_unsigned_v<T>, T>
SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
bool Dummy;
bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
@@ -654,7 +654,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
/// overflow. ResultOverflowed indicates if the result is larger than the
/// maximum representable value of type T.
template <typename T>
-std::enable_if_t<std::is_unsigned<T>::value, T>
+std::enable_if_t<std::is_unsigned_v<T>, T>
SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed = nullptr) {
bool Dummy;
bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
@@ -673,7 +673,7 @@ extern const float huge_valf;
/// Add two signed integers, computing the two's complement truncated result,
/// returning true if overflow occurred.
template <typename T>
-std::enable_if_t<std::is_signed<T>::value, T> AddOverflow(T X, T Y, T &Result) {
+std::enable_if_t<std::is_signed_v<T>, T> AddOverflow(T X, T Y, T &Result) {
#if __has_builtin(__builtin_add_overflow)
return __builtin_add_overflow(X, Y, &Result);
#else
@@ -699,7 +699,7 @@ std::enable_if_t<std::is_signed<T>::value, T> AddOverflow(T X, T Y, T &Result) {
/// Subtract two signed integers, computing the two's complement truncated
/// result, returning true if an overflow ocurred.
template <typename T>
-std::enable_if_t<std::is_signed<T>::value, T> SubOverflow(T X, T Y, T &Result) {
+std::enable_if_t<std::is_signed_v<T>, T> SubOverflow(T X, T Y, T &Result) {
#if __has_builtin(__builtin_sub_overflow)
return __builtin_sub_overflow(X, Y, &Result);
#else
@@ -725,7 +725,7 @@ std::enable_if_t<std::is_signed<T>::value, T> SubOverflow(T X, T Y, T &Result) {
/// Multiply two signed integers, computing the two's complement truncated
/// result, returning true if an overflow ocurred.
template <typename T>
-std::enable_if_t<std::is_signed<T>::value, T> MulOverflow(T X, T Y, T &Result) {
+std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
// Perform the unsigned multiplication on absolute values.
using U = std::make_unsigned_t<T>;
const U UX = X < 0 ? (0 - static_cast<U>(X)) : static_cast<U>(X);
diff --git a/llvm/include/llvm/Support/SwapByteOrder.h b/llvm/include/llvm/Support/SwapByteOrder.h
index ff4d0db66a6e8..a2cedc49467bd 100644
--- a/llvm/include/llvm/Support/SwapByteOrder.h
+++ b/llvm/include/llvm/Support/SwapByteOrder.h
@@ -106,7 +106,7 @@ inline double getSwappedBytes(double C) {
}
template <typename T>
-inline std::enable_if_t<std::is_enum<T>::value, T> getSwappedBytes(T C) {
+inline std::enable_if_t<std::is_enum_v<T>, T> getSwappedBytes(T C) {
return static_cast<T>(
llvm::byteswap(static_cast<std::underlying_type_t<T>>(C)));
}
diff --git a/llvm/include/llvm/Support/TrailingObjects.h b/llvm/include/llvm/Support/TrailingObjects.h
index f9e711a5dc177..f8a546b5c85aa 100644
--- a/llvm/include/llvm/Support/TrailingObjects.h
+++ b/llvm/include/llvm/Support/TrailingObjects.h
@@ -310,7 +310,7 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
/// that it's clear what the counts are counting in callers.
template <typename... Tys>
static constexpr std::enable_if_t<
- std::is_same<Foo<TrailingTys...>, Foo<Tys...>>::value, size_t>
+ std::is_same_v<Foo<TrailingTys...>, Foo<Tys...>>, size_t>
additionalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType<
TrailingTys, size_t>::type... Counts) {
return ParentType::additionalSizeToAllocImpl(0, Counts...);
@@ -322,7 +322,7 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
/// object.
template <typename... Tys>
static constexpr std::enable_if_t<
- std::is_same<Foo<TrailingTys...>, Foo<Tys...>>::value, size_t>
+ std::is_same_v<Foo<TrailingTys...>, Foo<Tys...>>, size_t>
totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType<
TrailingTys, size_t>::type... Counts) {
return sizeof(BaseTy) + ParentType::additionalSizeToAllocImpl(0, Counts...);
diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h
index 88b31aa6a0ab5..9683c82b2278f 100644
--- a/llvm/include/llvm/Support/TypeSize.h
+++ b/llvm/include/llvm/Support/TypeSize.h
@@ -133,7 +133,7 @@ template <typename LeafTy, typename ValueTy> class FixedOrScalableQuantity {
}
template <typename U = ScalarTy>
- friend constexpr std::enable_if_t<std::is_signed<U>::value, LeafTy>
+ friend constexpr std::enable_if_t<std::is_signed_v<U>, LeafTy>
operator-(const LeafTy &LHS) {
LeafTy Copy = LHS;
return Copy *= -1;
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index ef74f38671b58..3ed29821fa8f0 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -506,9 +506,7 @@ struct has_CustomMappingTraits
// has_FlowTraits<int> will cause an error with some compilers because
// it subclasses int. Using this wrapper only instantiates the
// real has_FlowTraits only if the template type is a class.
-template <typename T, bool Enabled = std::is_class<T>::value>
-class has_FlowTraits
-{
+template <typename T, bool Enabled = std::is_class_v<T>> class has_FlowTraits {
public:
static const bool value = false;
};
@@ -2011,8 +2009,7 @@ struct SequenceTraits<
// Sequences of fundamental types use flow formatting.
template <typename T>
-struct SequenceElementTraits<T,
- std::enable_if_t<std::is_fundamental<T>::value>> {
+struct SequenceElementTraits<T, std::enable_if_t<std::is_fundamental_v<T>>> {
static const bool flow = true;
};
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 7c42f355fd431..1e01eb9ea19c4 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -414,8 +414,8 @@ class raw_ostream {
/// Call the appropriate insertion operator, given an rvalue reference to a
/// raw_ostream object and return a stream of the same type as the argument.
template <typename OStream, typename T>
-std::enable_if_t<!std::is_reference<OStream>::value &&
- std::is_base_of<raw_ostream, OStream>::value,
+std::enable_if_t<!std::is_reference_v<OStream> &&
+ std::is_base_of_v<raw_ostream, OStream>,
OStream &&>
operator<<(OStream &&OS, const T &Value) {
OS << Value;
diff --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h
index a6046de87d1e3..86f07c19477d6 100644
--- a/llvm/include/llvm/Support/type_traits.h
+++ b/llvm/include/llvm/Support/type_traits.h
@@ -32,11 +32,11 @@ template <typename T> class is_integral_or_enum {
public:
static const bool value =
- !std::is_class<UnderlyingT>::value && // Filter conversion operators.
- !std::is_pointer<UnderlyingT>::value &&
- !std::is_floating_point<UnderlyingT>::value &&
- (std::is_enum<UnderlyingT>::value ||
- std::is_convertible<UnderlyingT, unsigned long long>::value);
+ !std::is_class_v<UnderlyingT> && // Filter conversion operators.
+ !std::is_pointer_v<UnderlyingT> &&
+ !std::is_floating_point_v<UnderlyingT> &&
+ (std::is_enum_v<UnderlyingT> ||
+ std::is_convertible_v<UnderlyingT, unsigned long long>);
};
/// If T is a pointer, just return it. If it is not, return T&.
@@ -45,7 +45,7 @@ struct add_lvalue_reference_if_not_pointer { using type = T &; };
template <typename T>
struct add_lvalue_reference_if_not_pointer<
- T, std::enable_if_t<std::is_pointer<T>::value>> {
+ T, std::enable_if_t<std::is_pointer_v<T>>> {
using type = T;
};
@@ -55,7 +55,7 @@ template<typename T, typename Enable = void>
struct add_const_past_pointer { using type = const T; };
template <typename T>
-struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer<T>::value>> {
+struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer_v<T>>> {
using type = const std::remove_pointer_t<T> *;
};
@@ -64,8 +64,7 @@ struct const_pointer_or_const_ref {
using type = const T &;
};
template <typename T>
-struct const_pointer_or_const_ref<T,
- std::enable_if_t<std::is_pointer<T>::value>> {
+struct const_pointer_or_const_ref<T, std::enable_if_t<std::is_pointer_v<T>>> {
using type = typename add_const_past_pointer<T>::type;
};
More information about the llvm-commits
mailing list