Bug 1625138 - Part 14: Replace mozilla::IsSigned with std::is_signed. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D68369

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2020-03-28 13:57:15 +00:00
Родитель 9ad58ea608
Коммит 13e9ad3137
11 изменённых файлов: 29 добавлений и 105 удалений

Просмотреть файл

@ -71,8 +71,8 @@ enum FromSignedness { FromIsSigned, FromIsUnsigned };
template <typename From, typename To,
FromSignedness =
IsSigned<From>::value ? FromIsSigned : FromIsUnsigned,
ToSignedness = IsSigned<To>::value ? ToIsSigned : ToIsUnsigned>
std::is_signed_v<From> ? FromIsSigned : FromIsUnsigned,
ToSignedness = std::is_signed_v<To> ? ToIsSigned : ToIsUnsigned>
struct BoundsCheckImpl;
// Implicit conversions on operands to binary operations make this all a bit

Просмотреть файл

@ -180,7 +180,7 @@ struct IsSupportedPass2<unsigned long long> {
template <typename IntegerType, size_t Size = sizeof(IntegerType)>
struct TwiceBiggerType {
typedef typename detail::StdintTypeForSizeAndSignedness<
sizeof(IntegerType) * 2, IsSigned<IntegerType>::value>::Type Type;
sizeof(IntegerType) * 2, std::is_signed_v<IntegerType>>::Type Type;
};
template <typename IntegerType>
@ -204,8 +204,8 @@ constexpr T BinaryComplement(T aX) {
return ~aX;
}
template <typename T, typename U, bool IsTSigned = IsSigned<T>::value,
bool IsUSigned = IsSigned<U>::value>
template <typename T, typename U, bool IsTSigned = std::is_signed_v<T>,
bool IsUSigned = std::is_signed_v<U>>
struct DoesRangeContainRange {};
template <typename T, typename U, bool Signedness>
@ -223,8 +223,8 @@ struct DoesRangeContainRange<T, U, false, true> {
static const bool value = false;
};
template <typename T, typename U, bool IsTSigned = IsSigned<T>::value,
bool IsUSigned = IsSigned<U>::value,
template <typename T, typename U, bool IsTSigned = std::is_signed_v<T>,
bool IsUSigned = std::is_signed_v<U>,
bool DoesTRangeContainURange = DoesRangeContainRange<T, U>::value>
struct IsInRangeImpl {};
@ -284,7 +284,7 @@ constexpr bool IsAddValid(T aX, T aY) {
std::make_unsigned_t<T> ux = aX;
std::make_unsigned_t<T> uy = aY;
std::make_unsigned_t<T> result = ux + uy;
return IsSigned<T>::value
return std::is_signed_v<T>
? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY))))
: BinaryComplement(aX) >= aY;
#endif
@ -303,13 +303,13 @@ constexpr bool IsSubValid(T aX, T aY) {
std::make_unsigned_t<T> uy = aY;
std::make_unsigned_t<T> result = ux - uy;
return IsSigned<T>::value
return std::is_signed_v<T>
? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY))))
: aX >= aY;
#endif
}
template <typename T, bool IsTSigned = IsSigned<T>::value,
template <typename T, bool IsTSigned = std::is_signed_v<T>,
bool TwiceBiggerTypeIsSupported =
IsSupported<typename TwiceBiggerType<T>::Type>::value>
struct IsMulValidImpl {};
@ -362,11 +362,11 @@ template <typename T>
constexpr bool IsDivValid(T aX, T aY) {
// Keep in mind that in the signed case, min/-1 is invalid because
// abs(min)>max.
return aY != 0 && !(IsSigned<T>::value &&
return aY != 0 && !(std::is_signed_v<T> &&
aX == std::numeric_limits<T>::min() && aY == T(-1));
}
template <typename T, bool IsTSigned = IsSigned<T>::value>
template <typename T, bool IsTSigned = std::is_signed_v<T>>
struct IsModValidImpl;
template <typename T>
@ -400,7 +400,7 @@ struct IsModValidImpl<T, true> {
}
};
template <typename T, bool IsSigned = IsSigned<T>::value>
template <typename T, bool IsSigned = std::is_signed_v<T>>
struct NegateImpl;
template <typename T>

Просмотреть файл

@ -359,7 +359,7 @@ template <typename Float, typename SignedInteger>
inline bool NumberEqualsSignedInteger(Float aValue, SignedInteger* aInteger) {
static_assert(IsSame<Float, float>::value || IsSame<Float, double>::value,
"Float must be an IEEE-754 floating point type");
static_assert(IsSigned<SignedInteger>::value,
static_assert(std::is_signed_v<SignedInteger>,
"this algorithm only works for signed types: a different one "
"will be required for unsigned types");
static_assert(sizeof(SignedInteger) >= sizeof(int),
@ -430,7 +430,7 @@ template <typename Float, typename SignedInteger>
inline bool NumberIsSignedInteger(Float aValue, SignedInteger* aInteger) {
static_assert(IsSame<Float, float>::value || IsSame<Float, double>::value,
"Float must be an IEEE-754 floating point type");
static_assert(IsSigned<SignedInteger>::value,
static_assert(std::is_signed_v<SignedInteger>,
"this algorithm only works for signed types: a different one "
"will be required for unsigned types");
static_assert(sizeof(SignedInteger) >= sizeof(int),

Просмотреть файл

@ -165,7 +165,7 @@ template <typename IntType1, typename IntType2>
detail::IntegerRange<IntType2> IntegerRange(IntType1 aBegin, IntType2 aEnd) {
static_assert(IsIntegral<IntType1>::value && IsIntegral<IntType2>::value,
"values must both be integral");
static_assert(IsSigned<IntType1>::value == IsSigned<IntType2>::value,
static_assert(std::is_signed_v<IntType1> == std::is_signed_v<IntType2>,
"signed/unsigned mismatch");
MOZ_ASSERT(aEnd >= aBegin, "End value should be larger than begin value");
return detail::IntegerRange<IntType2>(aBegin, aEnd);

Просмотреть файл

@ -270,40 +270,6 @@ struct IsPod<T*> : TrueType {};
namespace detail {
template <typename T, bool = IsFloatingPoint<T>::value,
bool = IsIntegral<T>::value,
typename NoCV = typename RemoveCV<T>::Type>
struct IsSignedHelper;
// Floating point is signed.
template <typename T, typename NoCV>
struct IsSignedHelper<T, true, false, NoCV> : TrueType {};
// Integral is conditionally signed.
template <typename T, typename NoCV>
struct IsSignedHelper<T, false, true, NoCV>
: IntegralConstant<bool, bool(NoCV(-1) < NoCV(1))> {};
// Non-floating point, non-integral is not signed.
template <typename T, typename NoCV>
struct IsSignedHelper<T, false, false, NoCV> : FalseType {};
} // namespace detail
/**
* IsSigned determines whether a type is a signed arithmetic type. |char| is
* considered a signed type if it has the same representation as |signed char|.
*
* mozilla::IsSigned<int>::value is true;
* mozilla::IsSigned<const unsigned int>::value is false;
* mozilla::IsSigned<unsigned char>::value is false;
* mozilla::IsSigned<float>::value is true.
*/
template <typename T>
struct IsSigned : detail::IsSignedHelper<T> {};
namespace detail {
struct DoIsDestructibleImpl {
template <typename T, typename = decltype(DeclVal<T&>().~T())>
static TrueType test(int);

Просмотреть файл

@ -105,7 +105,7 @@ template <typename T>
constexpr T ToResult(std::make_unsigned_t<T> aUnsigned) {
// We could *always* return WrapToSigned and rely on unsigned conversion to
// undo the wrapping when |T| is unsigned, but this seems clearer.
return IsSigned<T>::value ? WrapToSigned(aUnsigned) : aUnsigned;
return std::is_signed_v<T> ? WrapToSigned(aUnsigned) : aUnsigned;
}
template <typename T>

Просмотреть файл

@ -35,7 +35,7 @@ void verifyImplFunction(bool aX, bool aExpected, const char* aFile, int aLine,
#define VERIFY_IMPL(x, expected) \
verifyImplFunction((x), (expected), __FILE__, __LINE__, sizeof(T), \
IsSigned<T>::value)
std::is_signed_v<T>)
#define VERIFY(x) VERIFY_IMPL(x, true)
#define VERIFY_IS_FALSE(x) VERIFY_IMPL(x, false)
@ -49,8 +49,8 @@ struct testTwiceBiggerType {
VERIFY(
detail::IsSupported<typename detail::TwiceBiggerType<T>::Type>::value);
VERIFY(sizeof(typename detail::TwiceBiggerType<T>::Type) == 2 * sizeof(T));
VERIFY(bool(IsSigned<typename detail::TwiceBiggerType<T>::Type>::value) ==
bool(IsSigned<T>::value));
VERIFY(bool(std::is_signed_v<typename detail::TwiceBiggerType<T>::Type>) ==
bool(std::is_signed_v<T>));
}
};
@ -74,7 +74,7 @@ void test() {
alreadyRun = true;
VERIFY(detail::IsSupported<T>::value);
const bool isTSigned = IsSigned<T>::value;
const bool isTSigned = std::is_signed_v<T>;
VERIFY(bool(isTSigned) == !bool(T(-1) > T(0)));
testTwiceBiggerType<T>::run();
@ -82,7 +82,7 @@ void test() {
using unsignedT = std::make_unsigned_t<T>;
VERIFY(sizeof(unsignedT) == sizeof(T));
VERIFY(IsSigned<unsignedT>::value == false);
VERIFY(std::is_signed_v<unsignedT> == false);
const CheckedInt<T> max(std::numeric_limits<T>::max());
const CheckedInt<T> min(std::numeric_limits<T>::min());
@ -492,7 +492,7 @@ void test() {
#define VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE2(U, V, PostVExpr) \
{ \
bool isUSigned = IsSigned<U>::value; \
bool isUSigned = std::is_signed_v<U>; \
VERIFY_IS_VALID(CheckedInt<T>(V(0) PostVExpr)); \
VERIFY_IS_VALID(CheckedInt<T>(V(1) PostVExpr)); \
VERIFY_IS_VALID(CheckedInt<T>(V(100) PostVExpr)); \

Просмотреть файл

@ -16,7 +16,6 @@ using mozilla::IsConvertible;
using mozilla::IsDestructible;
using mozilla::IsFunction;
using mozilla::IsSame;
using mozilla::IsSigned;
using mozilla::RemoveExtent;
using mozilla::RemovePointer;
@ -29,50 +28,6 @@ static_assert(!IsArray<bool>::value, "bool not an array");
static_assert(IsArray<bool[]>::value, "bool[] is an array");
static_assert(IsArray<bool[5]>::value, "bool[5] is an array");
static_assert(!IsSigned<bool>::value, "bool shouldn't be signed");
static_assert(!IsSigned<const bool>::value, "const bool shouldn't be signed");
static_assert(!IsSigned<volatile bool>::value,
"volatile bool shouldn't be signed");
static_assert(!IsSigned<unsigned char>::value,
"unsigned char shouldn't be signed");
static_assert(IsSigned<signed char>::value, "signed char should be signed");
static_assert(!IsSigned<unsigned short>::value,
"unsigned short shouldn't be signed");
static_assert(IsSigned<short>::value, "short should be signed");
static_assert(!IsSigned<unsigned int>::value,
"unsigned int shouldn't be signed");
static_assert(IsSigned<int>::value, "int should be signed");
static_assert(!IsSigned<unsigned long>::value,
"unsigned long shouldn't be signed");
static_assert(IsSigned<long>::value, "long should be signed");
static_assert(IsSigned<float>::value, "float should be signed");
static_assert(IsSigned<const float>::value, "const float should be signed");
static_assert(IsSigned<double>::value, "double should be signed");
static_assert(IsSigned<volatile double>::value,
"volatile double should be signed");
static_assert(IsSigned<long double>::value, "long double should be signed");
static_assert(IsSigned<const volatile long double>::value,
"const volatile long double should be signed");
class NotIntConstructible {
NotIntConstructible(int) = delete;
};
static_assert(!IsSigned<NotIntConstructible>::value,
"non-arithmetic types are not signed");
class PublicDestructible {
public:
~PublicDestructible();

Просмотреть файл

@ -105,7 +105,7 @@ MFBT_API Result<LoadOrBranch, PCRelCheckError> CheckForPCRel(
*/
template <typename ResultT>
inline ResultT SignExtend(const uint32_t aValue, const uint8_t aNumValidBits) {
static_assert(IsIntegral<ResultT>::value && IsSigned<ResultT>::value,
static_assert(IsIntegral<ResultT>::value && std::is_signed_v<ResultT>,
"ResultT must be a signed integral type");
MOZ_ASSERT(aNumValidBits < 32U && aNumValidBits > 1);

Просмотреть файл

@ -7,6 +7,7 @@
#define SystemTimeConverter_h
#include <limits>
#include <type_traits>
#include "mozilla/TimeStamp.h"
#include "mozilla/TypeTraits.h"
@ -36,7 +37,7 @@ class SystemTimeConverter {
kTimeRange(std::numeric_limits<Time>::max()),
kTimeHalfRange(kTimeRange / 2),
kBackwardsSkewCheckInterval(Time(2000)) {
static_assert(!IsSigned<Time>::value, "Expected Time to be unsigned");
static_assert(!std::is_signed_v<Time>, "Expected Time to be unsigned");
}
template <typename CurrentTimeGetter>

Просмотреть файл

@ -7,6 +7,8 @@
#ifndef Tokenizer_h__
#define Tokenizer_h__
#include <type_traits>
#include "nsString.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/ScopeExit.h"
@ -384,7 +386,7 @@ class TTokenizer : public TokenizerBase<TChar> {
* Same as above, but accepts an integer with an optional minus sign.
*/
template <typename T, typename V = typename EnableIf<
IsSigned<typename RemovePointer<T>::Type>::value,
std::is_signed_v<typename RemovePointer<T>::Type>,
typename RemovePointer<T>::Type>::Type>
[[nodiscard]] bool ReadSignedInteger(T* aValue) {
MOZ_RELEASE_ASSERT(aValue);