Commit d74c23a2 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Make many base:: classes constexpr default constructible

Bug: 800760
Change-Id: Ib713771347283825ff53a8517b38a8abccd9d1bb
Reviewed-on: https://chromium-review.googlesource.com/860157
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#528805}
parent 906c0a08
......@@ -62,9 +62,6 @@
namespace base {
namespace subtle {
SpinLock::SpinLock() = default;
SpinLock::~SpinLock() = default;
void SpinLock::LockSlow() {
// The value of |kYieldProcessorTries| is cargo culted from TCMalloc, Windows
// critical section defaults, and various other recommendations.
......
......@@ -22,8 +22,8 @@ namespace subtle {
class BASE_EXPORT SpinLock {
public:
SpinLock();
~SpinLock();
constexpr SpinLock() = default;
~SpinLock() = default;
using Guard = std::lock_guard<SpinLock>;
ALWAYS_INLINE void lock() {
......
......@@ -45,12 +45,12 @@ template<>
class BASE_EXPORT JavaRef<jobject> {
public:
// Initializes a null reference. Don't add anything else here; it's inlined.
JavaRef() : obj_(nullptr) {}
constexpr JavaRef() : obj_(nullptr) {}
// Allow nullptr to be converted to JavaRef. This avoids having to declare an
// empty JavaRef just to pass null to a function, and makes C++ "nullptr" and
// Java "null" equivalent.
JavaRef(std::nullptr_t) : JavaRef() {}
constexpr JavaRef(std::nullptr_t) : JavaRef() {}
// Public to allow destruction of null JavaRef objects.
// Don't add anything else here; it's inlined.
......@@ -146,8 +146,8 @@ class JavaParamRef : public JavaRef<T> {
template<typename T>
class ScopedJavaLocalRef : public JavaRef<T> {
public:
ScopedJavaLocalRef() : env_(nullptr) {}
ScopedJavaLocalRef(std::nullptr_t) : env_(nullptr) {}
constexpr ScopedJavaLocalRef() : env_(nullptr) {}
constexpr ScopedJavaLocalRef(std::nullptr_t) : env_(nullptr) {}
// Non-explicit copy constructor, to allow ScopedJavaLocalRef to be returned
// by value as this is the normal usage pattern.
......@@ -234,8 +234,8 @@ class ScopedJavaLocalRef : public JavaRef<T> {
template<typename T>
class ScopedJavaGlobalRef : public JavaRef<T> {
public:
ScopedJavaGlobalRef() {}
ScopedJavaGlobalRef(std::nullptr_t) {}
constexpr ScopedJavaGlobalRef() {}
constexpr ScopedJavaGlobalRef(std::nullptr_t) {}
ScopedJavaGlobalRef(const ScopedJavaGlobalRef<T>& other) {
this->Reset(other);
......
......@@ -417,7 +417,7 @@ class circular_deque {
// ---------------------------------------------------------------------------
// Constructor
circular_deque() = default;
constexpr circular_deque() = default;
// Constructs with |count| copies of |value| or default constructed version.
circular_deque(size_type count) { resize(count); }
......
......@@ -37,7 +37,7 @@ namespace internal {
template <typename T>
class VectorBuffer {
public:
VectorBuffer() = default;
constexpr VectorBuffer() = default;
#if defined(__clang__) && !defined(__native_client__)
// This constructor converts an uninitialized void* to a T* which triggers
......
......@@ -15,7 +15,7 @@ namespace internal {
template <typename T>
struct ScopedDispatchObjectTraits {
static T InvalidValue() { return nullptr; }
static constexpr T InvalidValue() { return nullptr; }
static T Retain(T object) {
dispatch_retain(object);
return object;
......
......@@ -85,12 +85,12 @@ class scoped_nsprotocol
using Traits = internal::ScopedNSProtocolTraits<NST>;
#if !defined(__has_feature) || !__has_feature(objc_arc)
explicit scoped_nsprotocol(
explicit constexpr scoped_nsprotocol(
NST object = Traits::InvalidValue(),
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
: ScopedTypeRef<NST, Traits>(object, policy) {}
#else
explicit scoped_nsprotocol(NST object = Traits::InvalidValue())
explicit constexpr scoped_nsprotocol(NST object = Traits::InvalidValue())
: ScopedTypeRef<NST, Traits>(object, base::scoped_policy::RETAIN) {}
#endif
......@@ -149,12 +149,12 @@ class scoped_nsobject : public scoped_nsprotocol<NST*> {
using Traits = typename scoped_nsprotocol<NST*>::Traits;
#if !defined(__has_feature) || !__has_feature(objc_arc)
explicit scoped_nsobject(
explicit constexpr scoped_nsobject(
NST* object = Traits::InvalidValue(),
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
: scoped_nsprotocol<NST*>(object, policy) {}
#else
explicit scoped_nsobject(NST* object = Traits::InvalidValue())
explicit constexpr scoped_nsobject(NST* object = Traits::InvalidValue())
: scoped_nsprotocol<NST*>(object) {}
#endif
......@@ -198,12 +198,12 @@ class scoped_nsobject<id> : public scoped_nsprotocol<id> {
using Traits = typename scoped_nsprotocol<id>::Traits;
#if !defined(__has_feature) || !__has_feature(objc_arc)
explicit scoped_nsobject(
explicit constexpr scoped_nsobject(
id object = Traits::InvalidValue(),
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
: scoped_nsprotocol<id>(object, policy) {}
#else
explicit scoped_nsobject(id object = Traits::InvalidValue())
explicit constexpr scoped_nsobject(id object = Traits::InvalidValue())
: scoped_nsprotocol<id>(object) {}
#endif
......
......@@ -53,7 +53,7 @@ class ScopedTypeRef {
public:
typedef T element_type;
explicit ScopedTypeRef(
explicit constexpr ScopedTypeRef(
__unsafe_unretained T object = Traits::InvalidValue(),
base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
: object_(object) {
......
......@@ -148,8 +148,9 @@ class BASE_EXPORT RefCountedThreadSafeBase {
bool HasOneRef() const;
protected:
explicit RefCountedThreadSafeBase(StartRefCountFromZeroTag) {}
explicit RefCountedThreadSafeBase(StartRefCountFromOneTag) : ref_count_(1) {
explicit constexpr RefCountedThreadSafeBase(StartRefCountFromZeroTag) {}
explicit constexpr RefCountedThreadSafeBase(StartRefCountFromOneTag)
: ref_count_(1) {
#if DCHECK_IS_ON()
needs_adopt_ref_ = true;
#endif
......
......@@ -157,10 +157,10 @@ class scoped_refptr {
public:
typedef T element_type;
scoped_refptr() {}
constexpr scoped_refptr() = default;
// Constructs from raw pointer.
scoped_refptr(T* p) : ptr_(p) {
// Constructs from raw pointer. constexpr if |p| is null.
constexpr scoped_refptr(T* p) : ptr_(p) {
if (ptr_)
AddRef(ptr_);
}
......
......@@ -53,10 +53,6 @@ class DiscardableMemoryImpl : public DiscardableMemory {
} // namespace
TestDiscardableMemoryAllocator::TestDiscardableMemoryAllocator() = default;
TestDiscardableMemoryAllocator::~TestDiscardableMemoryAllocator() = default;
std::unique_ptr<DiscardableMemory>
TestDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) {
return std::make_unique<DiscardableMemoryImpl>(size);
......
......@@ -17,8 +17,7 @@ namespace base {
// DiscardableMemory instances backed by heap memory.
class TestDiscardableMemoryAllocator : public DiscardableMemoryAllocator {
public:
TestDiscardableMemoryAllocator();
~TestDiscardableMemoryAllocator() override;
constexpr TestDiscardableMemoryAllocator() = default;
// Overridden from DiscardableMemoryAllocator:
std::unique_ptr<DiscardableMemory> AllocateLockedDiscardableMemory(
......
......@@ -55,13 +55,9 @@ class PlatformThreadRef {
#elif defined(OS_POSIX)
typedef pthread_t RefType;
#endif
PlatformThreadRef()
: id_(0) {
}
constexpr PlatformThreadRef() : id_(0) {}
explicit PlatformThreadRef(RefType id)
: id_(id) {
}
explicit constexpr PlatformThreadRef(RefType id) : id_(id) {}
bool operator==(PlatformThreadRef other) const {
return id_ == other.id_;
......@@ -85,9 +81,9 @@ class PlatformThreadHandle {
typedef pthread_t Handle;
#endif
PlatformThreadHandle() : handle_(0) {}
constexpr PlatformThreadHandle() : handle_(0) {}
explicit PlatformThreadHandle(Handle handle) : handle_(handle) {}
explicit constexpr PlatformThreadHandle(Handle handle) : handle_(handle) {}
bool is_equal(const PlatformThreadHandle& other) const {
return handle_ == other.handle_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment