Skip to content

Commit

Permalink
Bug 1625138 - Part 12: Replace mozilla::IsPointer with std::is_pointe…
Browse files Browse the repository at this point in the history
…r. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D68366
  • Loading branch information
anba committed Mar 28, 2020
1 parent ad419b7 commit ec16111
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 68 deletions.
4 changes: 3 additions & 1 deletion browser/app/winlauncher/freestanding/SafeThreadLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef mozilla_freestanding_SafeThreadLocal_h
#define mozilla_freestanding_SafeThreadLocal_h

#include <type_traits>

#include "mozilla/NativeNt.h"
#include "mozilla/ThreadLocal.h"
#include "mozilla/TypeTraits.h"
Expand Down Expand Up @@ -46,7 +48,7 @@ class SafeThreadLocal final {

public:
static void set(T aValue) {
static_assert(mozilla::IsPointer<T>::value,
static_assert(std::is_pointer_v<T>,
"SafeThreadLocal must be used with a pointer");

if (sMainThreadId == mozilla::nt::RtlGetCurrentThreadId()) {
Expand Down
4 changes: 3 additions & 1 deletion mfbt/ThreadLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# include <pthread.h>
#endif

#include <type_traits>

#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/TypeTraits.h"
Expand Down Expand Up @@ -184,7 +186,7 @@ class ThreadLocal : public Storage<T> {

template <typename T, template <typename U> class Storage>
inline bool ThreadLocal<T, Storage>::init() {
static_assert(mozilla::IsPointer<T>::value || mozilla::IsIntegral<T>::value,
static_assert(std::is_pointer_v<T> || mozilla::IsIntegral<T>::value,
"mozilla::ThreadLocal must be used with a pointer or "
"integral type");
static_assert(sizeof(T) <= sizeof(void*),
Expand Down
28 changes: 0 additions & 28 deletions mfbt/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,34 +207,6 @@ struct IsFunPtr<Result (*)(ArgTypes...)> : public TrueType {};
template <typename T>
struct IsFunction : public detail::IsFunPtr<typename RemoveCV<T>::Type*> {};

namespace detail {

template <typename T>
struct IsPointerHelper : FalseType {};

template <typename T>
struct IsPointerHelper<T*> : TrueType {};

} // namespace detail

/**
* IsPointer determines whether a type is a possibly-CV-qualified pointer type
* (but not a pointer-to-member type).
*
* mozilla::IsPointer<struct S*>::value is true;
* mozilla::IsPointer<int*>::value is true;
* mozilla::IsPointer<int**>::value is true;
* mozilla::IsPointer<const int*>::value is true;
* mozilla::IsPointer<int* const>::value is true;
* mozilla::IsPointer<int* volatile>::value is true;
* mozilla::IsPointer<void (*)(void)>::value is true;
* mozilla::IsPointer<int>::value is false;
* mozilla::IsPointer<struct S>::value is false.
* mozilla::IsPointer<int(struct S::*)>::value is false
*/
template <typename T>
struct IsPointer : detail::IsPointerHelper<typename RemoveCV<T>::Type> {};

/* 20.9.4.3 Type properties [meta.unary.prop] */

/**
Expand Down
27 changes: 13 additions & 14 deletions mfbt/UniquePtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ class UniquePtr {
* Construct a UniquePtr containing |nullptr|.
*/
constexpr UniquePtr() : mTuple(static_cast<Pointer>(nullptr), DeleterType()) {
static_assert(!IsPointer<D>::value, "must provide a deleter instance");
static_assert(!std::is_pointer_v<D>, "must provide a deleter instance");
static_assert(!std::is_reference_v<D>, "must provide a deleter instance");
}

/**
* Construct a UniquePtr containing |aPtr|.
*/
explicit UniquePtr(Pointer aPtr) : mTuple(aPtr, DeleterType()) {
static_assert(!IsPointer<D>::value, "must provide a deleter instance");
static_assert(!std::is_pointer_v<D>, "must provide a deleter instance");
static_assert(!std::is_reference_v<D>, "must provide a deleter instance");
}

Expand Down Expand Up @@ -257,7 +257,7 @@ class UniquePtr {

MOZ_IMPLICIT
UniquePtr(decltype(nullptr)) : mTuple(nullptr, DeleterType()) {
static_assert(!IsPointer<D>::value, "must provide a deleter instance");
static_assert(!std::is_pointer_v<D>, "must provide a deleter instance");
static_assert(!std::is_reference_v<D>, "must provide a deleter instance");
}

Expand Down Expand Up @@ -351,15 +351,15 @@ class UniquePtr<T[], D> {
* Construct a UniquePtr containing nullptr.
*/
constexpr UniquePtr() : mTuple(static_cast<Pointer>(nullptr), DeleterType()) {
static_assert(!IsPointer<D>::value, "must provide a deleter instance");
static_assert(!std::is_pointer_v<D>, "must provide a deleter instance");
static_assert(!std::is_reference_v<D>, "must provide a deleter instance");
}

/**
* Construct a UniquePtr containing |aPtr|.
*/
explicit UniquePtr(Pointer aPtr) : mTuple(aPtr, DeleterType()) {
static_assert(!IsPointer<D>::value, "must provide a deleter instance");
static_assert(!std::is_pointer_v<D>, "must provide a deleter instance");
static_assert(!std::is_reference_v<D>, "must provide a deleter instance");
}

Expand All @@ -369,10 +369,9 @@ class UniquePtr<T[], D> {
// So forbid all overloads which would end up invoking delete[] on a pointer
// of the wrong type.
template <typename U>
UniquePtr(
U&& aU,
typename EnableIf<IsPointer<U>::value && IsConvertible<U, Pointer>::value,
int>::Type aDummy = 0) = delete;
UniquePtr(U&& aU, typename EnableIf<std::is_pointer_v<U> &&
IsConvertible<U, Pointer>::value,
int>::Type aDummy = 0) = delete;

UniquePtr(Pointer aPtr,
typename Conditional<std::is_reference_v<D>, D, const D&>::Type aD1)
Expand All @@ -390,18 +389,18 @@ class UniquePtr<T[], D> {

// Forbidden for the same reasons as stated above.
template <typename U, typename V>
UniquePtr(
U&& aU, V&& aV,
typename EnableIf<IsPointer<U>::value && IsConvertible<U, Pointer>::value,
int>::Type aDummy = 0) = delete;
UniquePtr(U&& aU, V&& aV,
typename EnableIf<std::is_pointer_v<U> &&
IsConvertible<U, Pointer>::value,
int>::Type aDummy = 0) = delete;

UniquePtr(UniquePtr&& aOther)
: mTuple(aOther.release(),
std::forward<DeleterType>(aOther.get_deleter())) {}

MOZ_IMPLICIT
UniquePtr(decltype(nullptr)) : mTuple(nullptr, DeleterType()) {
static_assert(!IsPointer<D>::value, "must provide a deleter instance");
static_assert(!std::is_pointer_v<D>, "must provide a deleter instance");
static_assert(!std::is_reference_v<D>, "must provide a deleter instance");
}

Expand Down
20 changes: 0 additions & 20 deletions mfbt/tests/TestTypeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ using mozilla::IsArray;
using mozilla::IsConvertible;
using mozilla::IsDestructible;
using mozilla::IsFunction;
using mozilla::IsPointer;
using mozilla::IsSame;
using mozilla::IsSigned;
using mozilla::IsUnsigned;
Expand All @@ -31,25 +30,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(!IsPointer<bool>::value, "bool not a pointer");
static_assert(IsPointer<bool*>::value, "bool* is a pointer");
static_assert(IsPointer<bool* const>::value, "bool* const is a pointer");
static_assert(IsPointer<bool* volatile>::value, "bool* volatile is a pointer");
static_assert(IsPointer<bool* const volatile>::value,
"bool* const volatile is a pointer");
static_assert(IsPointer<bool**>::value, "bool** is a pointer");
static_assert(IsPointer<void (*)(void)>::value, "void (*)(void) is a pointer");
struct IsPointerTest {
bool m;
void f();
};
static_assert(!IsPointer<IsPointerTest>::value, "IsPointerTest not a pointer");
static_assert(IsPointer<IsPointerTest*>::value, "IsPointerTest* is a pointer");
static_assert(!IsPointer<bool (IsPointerTest::*)()>::value,
"bool(IsPointerTest::*)() not a pointer");
static_assert(!IsPointer<void (IsPointerTest::*)(void)>::value,
"void(IsPointerTest::*)(void) not a pointer");

static_assert(!IsSigned<bool>::value, "bool shouldn't be signed");
static_assert(IsUnsigned<bool>::value, "bool should be unsigned");

Expand Down
3 changes: 2 additions & 1 deletion widget/BasicEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define mozilla_BasicEvents_h__

#include <stdint.h>
#include <type_traits>

#include "mozilla/EventForwards.h"
#include "mozilla/TimeStamp.h"
Expand Down Expand Up @@ -1049,7 +1050,7 @@ class NativeEventData final {

template <typename T>
void Copy(const T& other) {
static_assert(!mozilla::IsPointer<T>::value, "Don't want a pointer!");
static_assert(!std::is_pointer_v<T>, "Don't want a pointer!");
mBuffer.SetLength(sizeof(T));
memcpy(mBuffer.Elements(), &other, mBuffer.Length());
}
Expand Down
3 changes: 2 additions & 1 deletion xpcom/ds/nsTHashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define nsTHashtable_h__

#include <new>
#include <type_traits>
#include <utility>

#include "PLDHashTable.h"
Expand Down Expand Up @@ -78,7 +79,7 @@
template <class EntryType>
class MOZ_NEEDS_NO_VTABLE_TYPE nsTHashtable {
typedef mozilla::fallible_t fallible_t;
static_assert(mozilla::IsPointer<typename EntryType::KeyTypePointer>::value,
static_assert(std::is_pointer_v<typename EntryType::KeyTypePointer>,
"KeyTypePointer should be a pointer");

public:
Expand Down
4 changes: 3 additions & 1 deletion xpcom/threads/MozPromise.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#if !defined(MozPromise_h_)
# define MozPromise_h_

# include <type_traits>

# include "mozilla/Logging.h"
# include "mozilla/Maybe.h"
# include "mozilla/Monitor.h"
Expand Down Expand Up @@ -1427,7 +1429,7 @@ static RefPtr<PromiseType> InvokeAsync(
ActualArgTypes&&... aArgs) {
static_assert(
!detail::Any(
IsPointer<typename RemoveReference<ActualArgTypes>::Type>::value...),
std::is_pointer_v<typename RemoveReference<ActualArgTypes>::Type>...),
"Cannot pass pointer types through InvokeAsync, Storages must be "
"provided");
static_assert(sizeof...(ArgTypes) == sizeof...(ActualArgTypes),
Expand Down
2 changes: 1 addition & 1 deletion xpcom/threads/nsThreadUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ struct NonPointerStorageClass

template <typename T>
struct NonParameterStorageClass
: mozilla::Conditional<mozilla::IsPointer<T>::value,
: mozilla::Conditional<std::is_pointer_v<T>,
typename PointerStorageClass<
typename mozilla::RemovePointer<T>::Type>::Type,
typename NonPointerStorageClass<T>::Type> {};
Expand Down

0 comments on commit ec16111

Please sign in to comment.