зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1607595 - Manual fixups, and remove mozilla::IsBaseOf. r=froydnj
This is manual, but hopefully trivial. Differential Revision: https://phabricator.services.mozilla.com/D59014 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e363a41bd4
Коммит
f210527c4f
|
@ -33,7 +33,7 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
|
||||
// Struct that serves as a base class for all dictionaries. Particularly useful
|
||||
// so we can use IsBaseOf to detect dictionary template arguments.
|
||||
// so we can use std::is_base_of to detect dictionary template arguments.
|
||||
struct DictionaryBase {
|
||||
protected:
|
||||
bool ParseJSON(JSContext* aCx, const nsAString& aJSON,
|
||||
|
@ -75,12 +75,12 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
|||
}
|
||||
|
||||
// Struct that serves as a base class for all typed arrays and array buffers and
|
||||
// array buffer views. Particularly useful so we can use IsBaseOf to detect
|
||||
// array buffer views. Particularly useful so we can use std::is_base_of to detect
|
||||
// typed array/buffer/view template arguments.
|
||||
struct AllTypedArraysBase {};
|
||||
|
||||
// Struct that serves as a base class for all owning unions.
|
||||
// Particularly useful so we can use IsBaseOf to detect owning union
|
||||
// Particularly useful so we can use std::is_base_of to detect owning union
|
||||
// template arguments.
|
||||
struct AllOwningUnionBase {};
|
||||
|
||||
|
|
|
@ -821,8 +821,8 @@ struct IsRefcounted {
|
|||
|
||||
private:
|
||||
// This struct only works if T is fully declared (not just forward declared).
|
||||
// The IsBaseOf check will ensure that, we don't really need it for any other
|
||||
// reason (the static assert will of course always be true).
|
||||
// The std::is_base_of check will ensure that, we don't really need it for any
|
||||
// other reason (the static assert will of course always be true).
|
||||
static_assert(!std::is_base_of<nsISupports, T>::value || IsRefcounted::value,
|
||||
"Classes derived from nsISupports are refcounted!");
|
||||
};
|
||||
|
|
|
@ -57,7 +57,6 @@ using JS::MapTypeToTraceKind;
|
|||
|
||||
using mozilla::DebugOnly;
|
||||
using mozilla::IntegerRange;
|
||||
using mozilla::IsBaseOf;
|
||||
using mozilla::IsSame;
|
||||
using mozilla::PodCopy;
|
||||
|
||||
|
|
|
@ -663,81 +663,6 @@ struct IsSame<T, T> : TrueType {};
|
|||
|
||||
namespace detail {
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
|
||||
|
||||
template <class Base, class Derived>
|
||||
struct BaseOfTester : IntegralConstant<bool, __is_base_of(Base, Derived)> {};
|
||||
|
||||
#else
|
||||
|
||||
// The trickery used to implement IsBaseOf here makes it possible to use it for
|
||||
// the cases of private and multiple inheritance. This code was inspired by the
|
||||
// sample code here:
|
||||
//
|
||||
// http://stackoverflow.com/questions/2910979/how-is-base-of-works
|
||||
template <class Base, class Derived>
|
||||
struct BaseOfHelper {
|
||||
public:
|
||||
operator Base*() const;
|
||||
operator Derived*();
|
||||
};
|
||||
|
||||
template <class Base, class Derived>
|
||||
struct BaseOfTester {
|
||||
private:
|
||||
template <class T>
|
||||
static char test(Derived*, T);
|
||||
static int test(Base*, int);
|
||||
|
||||
public:
|
||||
static const bool value =
|
||||
sizeof(test(BaseOfHelper<Base, Derived>(), int())) == sizeof(char);
|
||||
};
|
||||
|
||||
template <class Base, class Derived>
|
||||
struct BaseOfTester<Base, const Derived> {
|
||||
private:
|
||||
template <class T>
|
||||
static char test(Derived*, T);
|
||||
static int test(Base*, int);
|
||||
|
||||
public:
|
||||
static const bool value =
|
||||
sizeof(test(BaseOfHelper<Base, Derived>(), int())) == sizeof(char);
|
||||
};
|
||||
|
||||
template <class Base, class Derived>
|
||||
struct BaseOfTester<Base&, Derived&> : FalseType {};
|
||||
|
||||
template <class Type>
|
||||
struct BaseOfTester<Type, Type> : TrueType {};
|
||||
|
||||
template <class Type>
|
||||
struct BaseOfTester<Type, const Type> : TrueType {};
|
||||
|
||||
#endif
|
||||
|
||||
} /* namespace detail */
|
||||
|
||||
/*
|
||||
* IsBaseOf allows to know whether a given class is derived from another.
|
||||
*
|
||||
* Consider the following class definitions:
|
||||
*
|
||||
* class A {};
|
||||
* class B : public A {};
|
||||
* class C {};
|
||||
*
|
||||
* std::is_base_of<A, A>::value is true;
|
||||
* std::is_base_of<A, B>::value is true;
|
||||
* std::is_base_of<A, C>::value is false;
|
||||
*/
|
||||
template <class Base, class Derived>
|
||||
struct IsBaseOf
|
||||
: IntegralConstant<bool, detail::BaseOfTester<Base, Derived>::value> {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename From, typename To>
|
||||
struct ConvertibleTester {
|
||||
private:
|
||||
|
|
|
@ -17,7 +17,6 @@ using mozilla::AddRvalueReference;
|
|||
using mozilla::Decay;
|
||||
using mozilla::DeclVal;
|
||||
using mozilla::IsArray;
|
||||
using mozilla::IsBaseOf;
|
||||
using mozilla::IsClass;
|
||||
using mozilla::IsConvertible;
|
||||
using mozilla::IsDefaultConstructible;
|
||||
|
@ -418,36 +417,6 @@ static_assert(!IsDestructible<PrivateDestructible>::value,
|
|||
static_assert(IsDestructible<TrivialDestructible>::value,
|
||||
"trivial destructible class is destructible");
|
||||
|
||||
namespace CPlusPlus11IsBaseOf {
|
||||
|
||||
// Adapted from C++11 § 20.9.6.
|
||||
struct B {};
|
||||
struct B1 : B {};
|
||||
struct B2 : B {};
|
||||
struct D : private B1, private B2 {};
|
||||
|
||||
static void StandardIsBaseOfTests() {
|
||||
static_assert((std::is_base_of<B, D>::value) == true,
|
||||
"IsBaseOf fails on diamond");
|
||||
static_assert((std::is_base_of<const B, D>::value) == true,
|
||||
"IsBaseOf fails on diamond plus constness change");
|
||||
static_assert((std::is_base_of<B, const D>::value) == true,
|
||||
"IsBaseOf fails on diamond plus constness change");
|
||||
static_assert((std::is_base_of<B, const B>::value) == true,
|
||||
"IsBaseOf fails on constness change");
|
||||
static_assert((std::is_base_of<D, B>::value) == false,
|
||||
"IsBaseOf got the direction of inheritance wrong");
|
||||
static_assert((std::is_base_of<B&, D&>::value) == false,
|
||||
"IsBaseOf should return false on references");
|
||||
static_assert((std::is_base_of<B[3], D[3]>::value) == false,
|
||||
"IsBaseOf should return false on arrays");
|
||||
// We fail at the following test. To fix it, we need to specialize IsBaseOf
|
||||
// for all built-in types.
|
||||
// static_assert((std::is_base_of<int, int>::value) == false);
|
||||
}
|
||||
|
||||
} /* namespace CPlusPlus11IsBaseOf */
|
||||
|
||||
class A {};
|
||||
class B : public A {};
|
||||
class C : private A {};
|
||||
|
@ -455,19 +424,6 @@ class D {};
|
|||
class E : public A {};
|
||||
class F : public B, public E {};
|
||||
|
||||
static void TestIsBaseOf() {
|
||||
static_assert((std::is_base_of<A, B>::value), "A is a base of B");
|
||||
static_assert((!std::is_base_of<B, A>::value), "B is not a base of A");
|
||||
static_assert((std::is_base_of<A, C>::value), "A is a base of C");
|
||||
static_assert((!std::is_base_of<C, A>::value), "C is not a base of A");
|
||||
static_assert((std::is_base_of<A, F>::value), "A is a base of F");
|
||||
static_assert((!std::is_base_of<F, A>::value), "F is not a base of A");
|
||||
static_assert((!std::is_base_of<A, D>::value), "A is not a base of D");
|
||||
static_assert((!std::is_base_of<D, A>::value), "D is not a base of A");
|
||||
static_assert((std::is_base_of<B, B>::value),
|
||||
"B is the same as B (and therefore, a base of B)");
|
||||
}
|
||||
|
||||
class ExplicitCopyConstructor {
|
||||
explicit ExplicitCopyConstructor(const ExplicitCopyConstructor&) = default;
|
||||
};
|
||||
|
@ -697,8 +653,6 @@ static_assert(mozilla::IsSame<unsigned int, uintptr_t>::value,
|
|||
#endif
|
||||
|
||||
int main() {
|
||||
CPlusPlus11IsBaseOf::StandardIsBaseOfTests();
|
||||
TestIsBaseOf();
|
||||
TestIsConvertible();
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче