Bug 1625138 - Part 4: Replace mozilla::MakeUnsigned with std::make_unsigned. r=froydnj

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2020-03-28 13:57:12 +00:00
Родитель 526c7e70fc
Коммит 1e4d8b891e
9 изменённых файлов: 30 добавлений и 149 удалений

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

@ -6,6 +6,8 @@
#include "CounterStyleManager.h"
#include <type_traits>
#include "mozilla/ArenaObjectID.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/CheckedInt.h"
@ -287,7 +289,7 @@ static bool CJKIdeographicToText(CounterValue aOrdinal, nsAString& aResult,
if (unitidx == 0) {
unit10Kidx = pos / 4;
}
auto cur = static_cast<MakeUnsigned<CounterValue>::Type>(aOrdinal) % 10;
auto cur = static_cast<std::make_unsigned_t<CounterValue>>(aOrdinal) % 10;
if (cur == 0) {
if (needZero) {
needZero = false;

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

@ -194,8 +194,7 @@ constexpr bool HasSignBit(T aX) {
// Notice that signed-to-unsigned conversions are always well-defined in the
// standard, as the value congruent modulo 2**n as expected. By contrast,
// unsigned-to-signed is only well-defined if the value is representable.
return bool(typename MakeUnsigned<T>::Type(aX) >>
PositionOfSignBit<T>::value);
return bool(std::make_unsigned_t<T>(aX) >> PositionOfSignBit<T>::value);
}
// Bitwise ops may return a larger type, so it's good to use this inline
@ -282,9 +281,9 @@ constexpr bool IsAddValid(T aX, T aY) {
// These bitwise operations can return a larger integer type, if T was a
// small type like int8_t, so we explicitly cast to T.
typename MakeUnsigned<T>::Type ux = aX;
typename MakeUnsigned<T>::Type uy = aY;
typename MakeUnsigned<T>::Type result = ux + uy;
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
? HasSignBit(BinaryComplement(T((result ^ aX) & (result ^ aY))))
: BinaryComplement(aX) >= aY;
@ -300,9 +299,9 @@ constexpr bool IsSubValid(T aX, T aY) {
// Subtraction is valid if either aX and aY have same sign, or aX-aY and aX
// have same sign. Since the value of aX-aY is undefined if we have a signed
// type, we compute it using the unsigned type of the same size.
typename MakeUnsigned<T>::Type ux = aX;
typename MakeUnsigned<T>::Type uy = aY;
typename MakeUnsigned<T>::Type result = ux - uy;
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
? HasSignBit(BinaryComplement(T((result ^ aX) & (aX ^ aY))))

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

@ -12,6 +12,8 @@
#ifndef mozilla_Latin1_h
#define mozilla_Latin1_h
#include <type_traits>
#include "mozilla/JsRust.h"
#include "mozilla/Span.h"
#include "mozilla/Tuple.h"
@ -32,7 +34,10 @@ namespace detail {
constexpr size_t kShortStringLimitForInlinePaths = 16;
template <typename Char>
class MakeUnsignedChar : public MakeUnsigned<Char> {};
class MakeUnsignedChar {
public:
using Type = std::make_unsigned_t<Char>;
};
template <>
class MakeUnsignedChar<char16_t> {

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

@ -690,9 +690,6 @@ struct RemoveReference<T&&> {
typedef T Type;
};
template <bool Condition, typename A, typename B>
struct Conditional;
namespace detail {
enum Voidness { TIsVoid, TIsNotVoid };
@ -730,95 +727,6 @@ struct AddRvalueReferenceHelper<T, TIsNotVoid> {
template <typename T>
struct AddRvalueReference : detail::AddRvalueReferenceHelper<T> {};
/* 20.9.7.3 Sign modifications [meta.trans.sign] */
template <bool B, typename T = void>
struct EnableIf;
namespace detail {
template <bool MakeConst, typename T>
struct WithC : Conditional<MakeConst, const T, T> {};
template <bool MakeVolatile, typename T>
struct WithV : Conditional<MakeVolatile, volatile T, T> {};
template <bool MakeConst, bool MakeVolatile, typename T>
struct WithCV : WithC<MakeConst, typename WithV<MakeVolatile, T>::Type> {};
template <typename T>
struct CorrespondingUnsigned;
template <>
struct CorrespondingUnsigned<char> {
typedef unsigned char Type;
};
template <>
struct CorrespondingUnsigned<signed char> {
typedef unsigned char Type;
};
template <>
struct CorrespondingUnsigned<short> {
typedef unsigned short Type;
};
template <>
struct CorrespondingUnsigned<int> {
typedef unsigned int Type;
};
template <>
struct CorrespondingUnsigned<long> {
typedef unsigned long Type;
};
template <>
struct CorrespondingUnsigned<long long> {
typedef unsigned long long Type;
};
template <typename T, typename CVRemoved = typename RemoveCV<T>::Type,
bool IsUnsignedIntegerType =
IsUnsigned<CVRemoved>::value && !IsSame<char, CVRemoved>::value>
struct MakeUnsigned;
template <typename T, typename CVRemoved>
struct MakeUnsigned<T, CVRemoved, true> {
typedef T Type;
};
template <typename T, typename CVRemoved>
struct MakeUnsigned<T, CVRemoved, false>
: WithCV<IsConst<T>::value, IsVolatile<T>::value,
typename CorrespondingUnsigned<CVRemoved>::Type> {};
} // namespace detail
/**
* MakeUnsigned produces the corresponding unsigned integer type for a given
* integral type T, with the const/volatile qualifiers of T. T must be a
* possibly-const/volatile-qualified integral type that isn't bool.
*
* If T is already an unsigned integer type (not including char!), then T is
* produced.
*
* Otherwise, if T is an signed integer type, the unsigned variety of T, with
* T's const/volatile qualifiers, is produced.
*
* Otherwise, the unsigned integral type of the same size as T, with the lowest
* rank, with T's const/volatile qualifiers, is produced. (This basically only
* acts to produce unsigned char when T = char.)
*
* mozilla::MakeUnsigned<signed long>::Type is unsigned long;
* mozilla::MakeUnsigned<volatile unsigned int>::Type is volatile unsigned int;
* mozilla::MakeUnsigned<const signed short>::Type is const unsigned short;
* mozilla::MakeUnsigned<const char>::Type is const unsigned char;
* mozilla::MakeUnsigned<bool> is an error;
* mozilla::MakeUnsigned<void*> is an error.
*/
template <typename T>
struct MakeUnsigned
: EnableIf<IsIntegral<T>::value &&
!IsSame<bool, typename RemoveCV<T>::Type>::value,
typename detail::MakeUnsigned<T> >::Type {};
/* 20.9.7.4 Array modifications [meta.trans.arr] */
/**
@ -915,7 +823,7 @@ struct AddPointer {
* ...
* };
*/
template <bool B, typename T>
template <bool B, typename T = void>
struct EnableIf {};
template <typename T>

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

@ -102,7 +102,7 @@ WrapToSigned(UnsignedType aValue) {
namespace detail {
template <typename T>
constexpr T ToResult(typename MakeUnsigned<T>::Type aUnsigned) {
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;
@ -111,7 +111,7 @@ constexpr T ToResult(typename MakeUnsigned<T>::Type aUnsigned) {
template <typename T>
struct WrappingAddHelper {
private:
using UnsignedT = typename MakeUnsigned<T>::Type;
using UnsignedT = std::make_unsigned_t<T>;
public:
MOZ_NO_SANITIZE_UNSIGNED_OVERFLOW
@ -159,7 +159,7 @@ namespace detail {
template <typename T>
struct WrappingSubtractHelper {
private:
using UnsignedT = typename MakeUnsigned<T>::Type;
using UnsignedT = std::make_unsigned_t<T>;
public:
MOZ_NO_SANITIZE_UNSIGNED_OVERFLOW
@ -205,7 +205,7 @@ namespace detail {
template <typename T>
struct WrappingMultiplyHelper {
private:
using UnsignedT = typename MakeUnsigned<T>::Type;
using UnsignedT = std::make_unsigned_t<T>;
public:
MOZ_NO_SANITIZE_UNSIGNED_OVERFLOW

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

@ -8,6 +8,7 @@
#include <iostream>
#include <climits>
#include <type_traits>
using namespace mozilla;
@ -78,7 +79,7 @@ void test() {
testTwiceBiggerType<T>::run();
typedef typename MakeUnsigned<T>::Type unsignedT;
using unsignedT = std::make_unsigned_t<T>;
VERIFY(sizeof(unsignedT) == sizeof(T));
VERIFY(IsSigned<unsignedT>::value == false);

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

@ -25,7 +25,6 @@ using mozilla::IsPointer;
using mozilla::IsSame;
using mozilla::IsSigned;
using mozilla::IsUnsigned;
using mozilla::MakeUnsigned;
using mozilla::RemoveExtent;
using mozilla::RemovePointer;
@ -401,40 +400,6 @@ static_assert(
"decltype should work using a DeclVal'd struct without a default "
"constructor");
static_assert(
IsSame<MakeUnsigned<const signed char>::Type, const unsigned char>::value,
"const signed char won't unsignify correctly");
static_assert(IsSame<MakeUnsigned<volatile signed short>::Type,
volatile unsigned short>::value,
"volatile signed short won't unsignify correctly");
static_assert(IsSame<MakeUnsigned<const volatile signed int>::Type,
const volatile unsigned int>::value,
"const volatile signed int won't unsignify correctly");
static_assert(IsSame<MakeUnsigned<signed long>::Type, unsigned long>::value,
"signed long won't unsignify correctly");
static_assert(
IsSame<MakeUnsigned<const unsigned char>::Type, const unsigned char>::value,
"const unsigned char won't unsignify correctly");
static_assert(IsSame<MakeUnsigned<volatile unsigned short>::Type,
volatile unsigned short>::value,
"volatile unsigned short won't unsignify correctly");
static_assert(IsSame<MakeUnsigned<const volatile unsigned int>::Type,
const volatile unsigned int>::value,
"const volatile unsigned int won't unsignify correctly");
static_assert(IsSame<MakeUnsigned<unsigned long>::Type, unsigned long>::value,
"signed long won't unsignify correctly");
static_assert(IsSame<MakeUnsigned<char>::Type, unsigned char>::value,
"char won't unsignify correctly");
static_assert(
IsSame<MakeUnsigned<volatile char>::Type, volatile unsigned char>::value,
"volatile char won't unsignify correctly");
static_assert(
IsSame<MakeUnsigned<const char>::Type, const unsigned char>::value,
"const char won't unsignify correctly");
static_assert(IsSame<RemoveExtent<int>::Type, int>::value,
"removing extent from non-array must return the non-array");
static_assert(

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

@ -7,6 +7,8 @@
#ifndef mozilla_interceptor_Arm64_h
#define mozilla_interceptor_Arm64_h
#include <type_traits>
#include "mozilla/Assertions.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/MathAlgorithms.h"
@ -107,8 +109,7 @@ inline ResultT SignExtend(const uint32_t aValue, const uint8_t aNumValidBits) {
"ResultT must be a signed integral type");
MOZ_ASSERT(aNumValidBits < 32U && aNumValidBits > 1);
using UnsignedResultT =
typename Decay<typename MakeUnsigned<ResultT>::Type>::Type;
using UnsignedResultT = typename Decay<std::make_unsigned_t<ResultT>>::Type;
const uint8_t kResultWidthBits = sizeof(ResultT) * 8;

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

@ -9,7 +9,7 @@
#ifndef mozilla_PerfectHash_h
#define mozilla_PerfectHash_h
#include "mozilla/TypeTraits.h"
#include <type_traits>
namespace mozilla {
namespace perfecthash {
@ -25,8 +25,8 @@ constexpr uint32_t FNV_PRIME = 16777619;
template <typename C>
inline uint32_t Hash(uint32_t aBasis, const C* aKey, size_t aLen) {
for (size_t i = 0; i < aLen; ++i) {
aBasis = (aBasis ^ static_cast<typename MakeUnsigned<C>::Type>(aKey[i])) *
FNV_PRIME;
aBasis =
(aBasis ^ static_cast<std::make_unsigned_t<C>>(aKey[i])) * FNV_PRIME;
}
return aBasis;
}
@ -47,4 +47,4 @@ inline const Entry& Lookup(const C* aKey, size_t aLen,
} // namespace perfecthash
} // namespace mozilla
#endif // !defined(mozilla_PerfectHash_h)
#endif // !defined(mozilla_PerfectHash_h)