зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1625138 - Part 27: Replace mozilla::DeclVal with std::declval. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68545 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
cae4e1fdbc
Коммит
42d4ebbda9
|
@ -8,6 +8,7 @@
|
|||
#define MediaEventSource_h_
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "mozilla/AbstractThread.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
|
@ -89,11 +90,11 @@ class TakeArgsHelper {
|
|||
template <typename C>
|
||||
static std::false_type test(void (C::*)() const volatile, int);
|
||||
template <typename F>
|
||||
static std::false_type test(F&&, decltype(DeclVal<F>()(), 0));
|
||||
static std::false_type test(F&&, decltype(std::declval<F>()(), 0));
|
||||
static std::true_type test(...);
|
||||
|
||||
public:
|
||||
typedef decltype(test(DeclVal<T>(), 0)) type;
|
||||
typedef decltype(test(std::declval<T>(), 0)) type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_dom_Promise_inl_h
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "mozilla/TupleCycleCollection.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
@ -81,7 +82,7 @@ using StorageType = typename StorageTypeHelper<std::decay_t<T>>::Type;
|
|||
// spec-compliant behavior there should still give us the expected results, MSVC
|
||||
// considers it an illegal use of std::forward.
|
||||
template <template <typename> class SmartPtr, typename T>
|
||||
decltype(DeclVal<SmartPtr<T>>().get()) ArgType(SmartPtr<T>& aVal) {
|
||||
decltype(std::declval<SmartPtr<T>>().get()) ArgType(SmartPtr<T>& aVal) {
|
||||
return aVal.get();
|
||||
}
|
||||
|
||||
|
|
|
@ -237,9 +237,9 @@ class Promise : public nsISupports, public SupportsWeakPtr<Promise> {
|
|||
template <typename Callback, typename... Args>
|
||||
using IsHandlerCallback =
|
||||
IsSame<already_AddRefed<Promise>,
|
||||
decltype(DeclVal<Callback>()((JSContext*)(nullptr),
|
||||
DeclVal<JS::Handle<JS::Value>>(),
|
||||
DeclVal<Args>()...))>;
|
||||
decltype(std::declval<Callback>()(
|
||||
(JSContext*)(nullptr), std::declval<JS::Handle<JS::Value>>(),
|
||||
std::declval<Args>()...))>;
|
||||
|
||||
template <typename Callback, typename... Args>
|
||||
using ThenResult =
|
||||
|
|
|
@ -166,13 +166,14 @@ namespace detail {
|
|||
template <typename Pointer>
|
||||
struct PointedTo {
|
||||
// Remove the reference that dereferencing operators may return.
|
||||
using Type = std::remove_reference_t<decltype(*DeclVal<Pointer>())>;
|
||||
using Type = std::remove_reference_t<decltype(*std::declval<Pointer>())>;
|
||||
using NonConstType = typename RemoveConst<Type>::Type;
|
||||
};
|
||||
|
||||
// Specializations for raw pointers.
|
||||
// This is especially required because VS 2017 15.6 (March 2018) started
|
||||
// rejecting the above `decltype(*DeclVal<Pointer>())` trick for raw pointers.
|
||||
// rejecting the above `decltype(*std::declval<Pointer>())` trick for raw
|
||||
// pointers.
|
||||
// See bug 1443367.
|
||||
template <typename T>
|
||||
struct PointedTo<T*> {
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#ifndef mozilla_ReverseIterator_h
|
||||
#define mozilla_ReverseIterator_h
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
|
@ -26,7 +28,7 @@ class ReverseIterator {
|
|||
MOZ_IMPLICIT ReverseIterator(const ReverseIterator<Iterator>& aOther)
|
||||
: mCurrent(aOther.mCurrent) {}
|
||||
|
||||
decltype(*DeclVal<IteratorT>()) operator*() const {
|
||||
decltype(*std::declval<IteratorT>()) operator*() const {
|
||||
IteratorT tmp = mCurrent;
|
||||
return *--tmp;
|
||||
}
|
||||
|
|
32
mfbt/Span.h
32
mfbt/Span.h
|
@ -465,28 +465,28 @@ class Span {
|
|||
/**
|
||||
* Constructor for standard-library containers.
|
||||
*/
|
||||
template <class Container,
|
||||
class = std::enable_if_t<
|
||||
!span_details::is_span<Container>::value &&
|
||||
!span_details::is_std_array<Container>::value &&
|
||||
std::is_convertible_v<typename Container::pointer, pointer> &&
|
||||
std::is_convertible_v<
|
||||
typename Container::pointer,
|
||||
decltype(mozilla::DeclVal<Container>().data())>>>
|
||||
template <
|
||||
class Container,
|
||||
class = std::enable_if_t<
|
||||
!span_details::is_span<Container>::value &&
|
||||
!span_details::is_std_array<Container>::value &&
|
||||
std::is_convertible_v<typename Container::pointer, pointer> &&
|
||||
std::is_convertible_v<typename Container::pointer,
|
||||
decltype(std::declval<Container>().data())>>>
|
||||
constexpr MOZ_IMPLICIT Span(Container& cont)
|
||||
: Span(cont.data(), ReleaseAssertedCast<index_type>(cont.size())) {}
|
||||
|
||||
/**
|
||||
* Constructor for standard-library containers (const version).
|
||||
*/
|
||||
template <class Container,
|
||||
class = std::enable_if_t<
|
||||
std::is_const_v<element_type> &&
|
||||
!span_details::is_span<Container>::value &&
|
||||
std::is_convertible_v<typename Container::pointer, pointer> &&
|
||||
std::is_convertible_v<
|
||||
typename Container::pointer,
|
||||
decltype(mozilla::DeclVal<Container>().data())>>>
|
||||
template <
|
||||
class Container,
|
||||
class = std::enable_if_t<
|
||||
std::is_const_v<element_type> &&
|
||||
!span_details::is_span<Container>::value &&
|
||||
std::is_convertible_v<typename Container::pointer, pointer> &&
|
||||
std::is_convertible_v<typename Container::pointer,
|
||||
decltype(std::declval<Container>().data())>>>
|
||||
constexpr MOZ_IMPLICIT Span(const Container& cont)
|
||||
: Span(cont.data(), ReleaseAssertedCast<index_type>(cont.size())) {}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include "mozilla/Types.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
/*
|
||||
* These traits are approximate copies of the traits and semantics from C++11's
|
||||
* <type_traits> header. Don't add traits not in that header! When all
|
||||
|
@ -23,19 +25,6 @@ namespace mozilla {
|
|||
|
||||
template <typename>
|
||||
struct RemoveCV;
|
||||
template <typename>
|
||||
struct AddRvalueReference;
|
||||
|
||||
/* 20.2.4 Function template declval [declval] */
|
||||
|
||||
/**
|
||||
* DeclVal simplifies the definition of expressions which occur as unevaluated
|
||||
* operands. It converts T to a reference type, making it possible to use in
|
||||
* decltype expressions even if T does not have a default constructor, e.g.:
|
||||
* decltype(DeclVal<TWithNoDefaultConstructor>().foo())
|
||||
*/
|
||||
template <typename T>
|
||||
typename AddRvalueReference<T>::Type DeclVal();
|
||||
|
||||
/* 20.9.3 Helper classes [meta.help] */
|
||||
|
||||
|
@ -130,7 +119,7 @@ struct IsPod<T*> : TrueType {};
|
|||
namespace detail {
|
||||
|
||||
struct DoIsDestructibleImpl {
|
||||
template <typename T, typename = decltype(DeclVal<T&>().~T())>
|
||||
template <typename T, typename = decltype(std::declval<T&>().~T())>
|
||||
static TrueType test(int);
|
||||
template <typename T>
|
||||
static FalseType test(...);
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
using mozilla::AddRvalueReference;
|
||||
using mozilla::DeclVal;
|
||||
using mozilla::IsDestructible;
|
||||
using mozilla::IsSame;
|
||||
|
||||
|
@ -43,24 +42,6 @@ static_assert(IsSame<AddRvalueReference<void>::Type, void>::value,
|
|||
static_assert(IsSame<AddRvalueReference<struct S1&>::Type, struct S1&>::value,
|
||||
"not reference-collapsing struct S1& && to struct S1& correctly");
|
||||
|
||||
struct TestWithDefaultConstructor {
|
||||
int foo() const { return 0; }
|
||||
};
|
||||
struct TestWithNoDefaultConstructor {
|
||||
explicit TestWithNoDefaultConstructor(int) {}
|
||||
int foo() const { return 1; }
|
||||
};
|
||||
|
||||
static_assert(IsSame<decltype(TestWithDefaultConstructor().foo()), int>::value,
|
||||
"decltype should work using a struct with a default constructor");
|
||||
static_assert(
|
||||
IsSame<decltype(DeclVal<TestWithDefaultConstructor>().foo()), int>::value,
|
||||
"decltype should work using a DeclVal'd struct with a default constructor");
|
||||
static_assert(
|
||||
IsSame<decltype(DeclVal<TestWithNoDefaultConstructor>().foo()), int>::value,
|
||||
"decltype should work using a DeclVal'd struct without a default "
|
||||
"constructor");
|
||||
|
||||
/*
|
||||
* Android's broken [u]intptr_t inttype macros are broken because its PRI*PTR
|
||||
* macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t)
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#ifndef mozilla_extensions_MatchPattern_h
|
||||
#define mozilla_extensions_MatchPattern_h
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/MatchPatternBinding.h"
|
||||
#include "mozilla/extensions/MatchGlob.h"
|
||||
|
@ -95,11 +97,11 @@ class AtomSet final : public RefCounted<AtomSet> {
|
|||
}
|
||||
}
|
||||
|
||||
auto begin() const -> decltype(DeclVal<const ArrayType>().begin()) {
|
||||
auto begin() const -> decltype(std::declval<const ArrayType>().begin()) {
|
||||
return mElems.begin();
|
||||
}
|
||||
|
||||
auto end() const -> decltype(DeclVal<const ArrayType>().end()) {
|
||||
auto end() const -> decltype(std::declval<const ArrayType>().end()) {
|
||||
return mElems.end();
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ namespace mozilla {
|
|||
// variety of smart pointer types in addition to raw pointers. These types
|
||||
// include RefPtr<>, nsCOMPtr<>, and OwningNonNull<>.
|
||||
template <class T>
|
||||
using PointedToType = std::remove_pointer_t<decltype(&*mozilla::DeclVal<T>())>;
|
||||
using PointedToType = std::remove_pointer_t<decltype(&*std::declval<T>())>;
|
||||
} // namespace mozilla
|
||||
|
||||
#ifdef NSCAP_FEATURE_USE_BASE
|
||||
|
|
|
@ -911,9 +911,8 @@ template <typename T, typename U, typename V = int>
|
|||
struct IsCompareMethod : mozilla::FalseType {};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct IsCompareMethod<T, U,
|
||||
decltype(mozilla::DeclVal<T>()(mozilla::DeclVal<U>(),
|
||||
mozilla::DeclVal<U>()))>
|
||||
struct IsCompareMethod<
|
||||
T, U, decltype(std::declval<T>()(std::declval<U>(), std::declval<U>()))>
|
||||
: mozilla::TrueType {};
|
||||
|
||||
// These two wrappers allow us to use either a tri-state comparator, or an
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include <stdint.h>
|
||||
#include <utility>
|
||||
#include "nsString.h"
|
||||
|
||||
extern "C" {
|
||||
|
@ -22,23 +23,23 @@ void GTest_ExpectFailure(const char* aMessage) { EXPECT_STREQ(aMessage, ""); }
|
|||
SIZE_ALIGN_CHECK(nsString)
|
||||
SIZE_ALIGN_CHECK(nsCString)
|
||||
|
||||
#define MEMBER_CHECK(Clazz, Member) \
|
||||
extern "C" void Rust_Test_Member_##Clazz##_##Member( \
|
||||
size_t* size, size_t* align, size_t* offset); \
|
||||
TEST(RustNsString, ReprMember_##Clazz##_##Member) \
|
||||
{ \
|
||||
class Hack : public Clazz { \
|
||||
public: \
|
||||
static void RunTest() { \
|
||||
size_t size, align, offset; \
|
||||
Rust_Test_Member_##Clazz##_##Member(&size, &align, &offset); \
|
||||
EXPECT_EQ(size, sizeof(mozilla::DeclVal<Hack>().Member)); \
|
||||
EXPECT_EQ(align, alignof(decltype(mozilla::DeclVal<Hack>().Member))); \
|
||||
EXPECT_EQ(offset, offsetof(Hack, Member)); \
|
||||
} \
|
||||
}; \
|
||||
static_assert(sizeof(Clazz) == sizeof(Hack), "Hack matches class"); \
|
||||
Hack::RunTest(); \
|
||||
#define MEMBER_CHECK(Clazz, Member) \
|
||||
extern "C" void Rust_Test_Member_##Clazz##_##Member( \
|
||||
size_t* size, size_t* align, size_t* offset); \
|
||||
TEST(RustNsString, ReprMember_##Clazz##_##Member) \
|
||||
{ \
|
||||
class Hack : public Clazz { \
|
||||
public: \
|
||||
static void RunTest() { \
|
||||
size_t size, align, offset; \
|
||||
Rust_Test_Member_##Clazz##_##Member(&size, &align, &offset); \
|
||||
EXPECT_EQ(size, sizeof(std::declval<Hack>().Member)); \
|
||||
EXPECT_EQ(align, alignof(decltype(std::declval<Hack>().Member))); \
|
||||
EXPECT_EQ(offset, offsetof(Hack, Member)); \
|
||||
} \
|
||||
}; \
|
||||
static_assert(sizeof(Clazz) == sizeof(Hack), "Hack matches class"); \
|
||||
Hack::RunTest(); \
|
||||
}
|
||||
|
||||
MEMBER_CHECK(nsString, mData)
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
#include "mozilla/TypeTraits.h"
|
||||
#include <stdio.h>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
using mozilla::DeclVal;
|
||||
using mozilla::IsSame;
|
||||
|
||||
/**************************************************************
|
||||
|
@ -346,10 +346,10 @@ TEST(NsDeque, TestConstRangeFor)
|
|||
}
|
||||
|
||||
static_assert(IsSame<nsDeque::ConstDequeIterator,
|
||||
decltype(DeclVal<const nsDeque&>().begin())>::value,
|
||||
decltype(std::declval<const nsDeque&>().begin())>::value,
|
||||
"(const nsDeque).begin() should return ConstDequeIterator");
|
||||
static_assert(IsSame<nsDeque::ConstDequeIterator,
|
||||
decltype(DeclVal<const nsDeque&>().end())>::value,
|
||||
decltype(std::declval<const nsDeque&>().end())>::value,
|
||||
"(const nsDeque).end() should return ConstDequeIterator");
|
||||
|
||||
int sum = 0;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
# define MozPromise_h_
|
||||
|
||||
# include <type_traits>
|
||||
# include <utility>
|
||||
|
||||
# include "mozilla/Logging.h"
|
||||
# include "mozilla/Maybe.h"
|
||||
|
@ -884,8 +885,8 @@ class MozPromise : public MozPromiseBase {
|
|||
}
|
||||
|
||||
template <typename... Ts>
|
||||
auto Then(Ts&&... aArgs)
|
||||
-> decltype(DeclVal<PromiseType>().Then(std::forward<Ts>(aArgs)...)) {
|
||||
auto Then(Ts&&... aArgs) -> decltype(
|
||||
std::declval<PromiseType>().Then(std::forward<Ts>(aArgs)...)) {
|
||||
return static_cast<RefPtr<PromiseType>>(*this)->Then(
|
||||
std::forward<Ts>(aArgs)...);
|
||||
}
|
||||
|
|
|
@ -1036,8 +1036,8 @@ struct SFINAE1True : mozilla::TrueType {};
|
|||
|
||||
template <class T>
|
||||
static auto HasRefCountMethodsTest(int)
|
||||
-> SFINAE1True<decltype(mozilla::DeclVal<T>().AddRef(),
|
||||
mozilla::DeclVal<T>().Release())>;
|
||||
-> SFINAE1True<decltype(std::declval<T>().AddRef(),
|
||||
std::declval<T>().Release())>;
|
||||
template <class>
|
||||
static auto HasRefCountMethodsTest(long) -> mozilla::FalseType;
|
||||
|
||||
|
@ -1135,7 +1135,7 @@ struct ParameterStorage
|
|||
|
||||
template <class T>
|
||||
static auto HasSetDeadlineTest(int) -> SFINAE1True<decltype(
|
||||
mozilla::DeclVal<T>().SetDeadline(mozilla::DeclVal<mozilla::TimeStamp>()))>;
|
||||
std::declval<T>().SetDeadline(std::declval<mozilla::TimeStamp>()))>;
|
||||
|
||||
template <class T>
|
||||
static auto HasSetDeadlineTest(long) -> mozilla::FalseType;
|
||||
|
|
Загрузка…
Ссылка в новой задаче