Skip to content

Commit bb94014

Browse files
committedFeb 12, 2020
Bug 1613985 - Use default for equivalent-to-default constructors/destructors in mfbt. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D62542
1 parent 2812c91 commit bb94014

20 files changed

+48
-95
lines changed
 

‎mfbt/Array.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Array {
2828
using ElementType = T;
2929
static constexpr size_t Length = _Length;
3030

31-
Array() {}
31+
Array() = default;
3232

3333
template <typename... Args>
3434
MOZ_IMPLICIT constexpr Array(Args&&... aArgs)

‎mfbt/Atomics.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct AutoRecordAtomicAccess;
160160
template <>
161161
struct AutoRecordAtomicAccess<recordreplay::Behavior::DontPreserve> {
162162
explicit AutoRecordAtomicAccess(const void* aValue) {}
163-
~AutoRecordAtomicAccess() {}
163+
~AutoRecordAtomicAccess() = default;
164164
};
165165

166166
template <>

‎mfbt/DebugOnly.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MOZ_STACK_CLASS DebugOnly {
4141
#ifdef DEBUG
4242
T value;
4343

44-
DebugOnly() {}
44+
DebugOnly() = default;
4545
MOZ_IMPLICIT DebugOnly(const T& aOther) : value(aOther) {}
4646
DebugOnly(const DebugOnly& aOther) : value(aOther.value) {}
4747
DebugOnly& operator=(const T& aRhs) {
@@ -65,7 +65,7 @@ class MOZ_STACK_CLASS DebugOnly {
6565
const T& operator->() const { return value; }
6666

6767
#else
68-
DebugOnly() {}
68+
DebugOnly() = default;
6969
MOZ_IMPLICIT DebugOnly(const T&) {}
7070
DebugOnly(const DebugOnly&) {}
7171
DebugOnly& operator=(const T&) { return *this; }
@@ -79,7 +79,7 @@ class MOZ_STACK_CLASS DebugOnly {
7979
#endif
8080

8181
/*
82-
* DebugOnly must always have a destructor or else it will
82+
* DebugOnly must always have a user-defined destructor or else it will
8383
* generate "unused variable" warnings, exactly what it's intended
8484
* to avoid!
8585
*/

‎mfbt/EnumeratedArray.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EnumeratedArray {
5050
ArrayType mArray;
5151

5252
public:
53-
EnumeratedArray() {}
53+
EnumeratedArray() = default;
5454

5555
template <typename... Args>
5656
MOZ_IMPLICIT constexpr EnumeratedArray(Args&&... aArgs)

‎mfbt/HashTable.h

+8-18
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,8 @@ class HashMap {
178178
explicit HashMap(uint32_t aLen) : mImpl(AllocPolicy(), aLen) {}
179179

180180
// HashMap is movable.
181-
HashMap(HashMap&& aRhs) : mImpl(std::move(aRhs.mImpl)) {}
182-
void operator=(HashMap&& aRhs) {
183-
MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited");
184-
mImpl = std::move(aRhs.mImpl);
185-
}
181+
HashMap(HashMap&& aRhs) = default;
182+
HashMap& operator=(HashMap&& aRhs) = default;
186183

187184
// -- Status and sizing ----------------------------------------------------
188185

@@ -463,11 +460,8 @@ class HashSet {
463460
explicit HashSet(uint32_t aLen) : mImpl(AllocPolicy(), aLen) {}
464461

465462
// HashSet is movable.
466-
HashSet(HashSet&& aRhs) : mImpl(std::move(aRhs.mImpl)) {}
467-
void operator=(HashSet&& aRhs) {
468-
MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited");
469-
mImpl = std::move(aRhs.mImpl);
470-
}
463+
HashSet(HashSet&& aRhs) = default;
464+
HashSet& operator=(HashSet&& aRhs) = default;
471465

472466
// -- Status and sizing ----------------------------------------------------
473467

@@ -911,13 +905,8 @@ class HashMapEntry {
911905
: key_(std::forward<KeyInput>(aKey)),
912906
value_(std::forward<ValueInput>(aValue)) {}
913907

914-
HashMapEntry(HashMapEntry&& aRhs)
915-
: key_(std::move(aRhs.key_)), value_(std::move(aRhs.value_)) {}
916-
917-
void operator=(HashMapEntry&& aRhs) {
918-
key_ = std::move(aRhs.key_);
919-
value_ = std::move(aRhs.value_);
920-
}
908+
HashMapEntry(HashMapEntry&& aRhs) = default;
909+
HashMapEntry& operator=(HashMapEntry&& aRhs) = default;
921910

922911
using KeyType = Key;
923912
using ValueType = Value;
@@ -1514,13 +1503,14 @@ class HashTable : private AllocPolicy {
15141503

15151504
// HashTable is movable
15161505
HashTable(HashTable&& aRhs) : AllocPolicy(std::move(aRhs)) { moveFrom(aRhs); }
1517-
void operator=(HashTable&& aRhs) {
1506+
HashTable& operator=(HashTable&& aRhs) {
15181507
MOZ_ASSERT(this != &aRhs, "self-move assignment is prohibited");
15191508
if (mTable) {
15201509
destroyTable(*this, mTable, capacity());
15211510
}
15221511
AllocPolicy::operator=(std::move(aRhs));
15231512
moveFrom(aRhs);
1513+
return *this;
15241514
}
15251515

15261516
private:

‎mfbt/JSONWriter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ namespace mozilla {
110110
class JSONWriteFunc {
111111
public:
112112
virtual void Write(const char* aStr) = 0;
113-
virtual ~JSONWriteFunc() {}
113+
virtual ~JSONWriteFunc() = default;
114114
};
115115

116116
// Ideally this would be within |EscapedString| but when compiling with GCC

‎mfbt/LinkedList.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,7 @@ class AutoCleanLinkedList : public LinkedList<T> {
620620
public:
621621
~AutoCleanLinkedList() { clear(); }
622622

623-
AutoCleanLinkedList& operator=(AutoCleanLinkedList&& aOther) {
624-
LinkedList<T>::operator=(std::forward<LinkedList<T>>(aOther));
625-
return *this;
626-
}
623+
AutoCleanLinkedList& operator=(AutoCleanLinkedList&& aOther) = default;
627624

628625
void clear() {
629626
while (ClientType element = this->popFirst()) {

‎mfbt/Opaque.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Opaque final {
2626
T mValue;
2727

2828
public:
29-
Opaque() {}
29+
Opaque() = default;
3030
explicit Opaque(T aValue) : mValue(aValue) {}
3131

3232
bool operator==(const Opaque& aOther) const {

‎mfbt/Pair.h

+2-12
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,10 @@ struct Pair : private detail::PairHelper<A, B> {
142142
Pair(AArg&& aA, BArg&& aB)
143143
: Base(std::forward<AArg>(aA), std::forward<BArg>(aB)) {}
144144

145-
Pair(Pair&& aOther)
146-
: Base(std::move(aOther.first()), std::move(aOther.second())) {}
147-
145+
Pair(Pair&& aOther) = default;
148146
Pair(const Pair& aOther) = default;
149147

150-
Pair& operator=(Pair&& aOther) {
151-
MOZ_ASSERT(this != &aOther, "Self-moves are prohibited");
152-
153-
first() = std::move(aOther.first());
154-
second() = std::move(aOther.second());
155-
156-
return *this;
157-
}
158-
148+
Pair& operator=(Pair&& aOther) = default;
159149
Pair& operator=(const Pair& aOther) = default;
160150

161151
/** The A instance. */

‎mfbt/RecordReplay.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void Initialize(int aArgc, char* aArgv[]) {
138138
// Record/replay API functions can't GC, but we can't use
139139
// JS::AutoSuppressGCAnalysis here due to linking issues.
140140
struct AutoSuppressGCAnalysis {
141-
AutoSuppressGCAnalysis() {}
141+
AutoSuppressGCAnalysis() = default;
142142
~AutoSuppressGCAnalysis() {
143143
#ifdef DEBUG
144144
// Need nontrivial destructor.

‎mfbt/RollingMean.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,7 @@ class RollingMean {
4444
MOZ_ASSERT(aMaxValues > 0);
4545
}
4646

47-
RollingMean& operator=(RollingMean&& aOther) {
48-
MOZ_ASSERT(this != &aOther, "self-assignment is forbidden");
49-
this->~RollingMean();
50-
new (this) RollingMean(aOther.mMaxValues);
51-
mInsertIndex = aOther.mInsertIndex;
52-
mTotal = aOther.mTotal;
53-
mValues.swap(aOther.mValues);
54-
return *this;
55-
}
47+
RollingMean& operator=(RollingMean&& aOther) = default;
5648

5749
/**
5850
* Insert a value into the rolling mean.

‎mfbt/Scoped.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ class MOZ_NON_TEMPORARY_CLASS Scoped {
174174
Super::operator=(aRhs); \
175175
return *this; \
176176
} \
177-
name& operator=(name&& aRhs) { \
178-
Super::operator=(std::move(aRhs)); \
179-
return *this; \
180-
} \
177+
name& operator=(name&& aRhs) = default; \
178+
\
181179
explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \
182180
: Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) {} \
183181
explicit name(Resource aRhs MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \
@@ -186,8 +184,8 @@ class MOZ_NON_TEMPORARY_CLASS Scoped {
186184
: Super(std::move(aRhs) MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) {} \
187185
\
188186
private: \
189-
explicit name(name&) = delete; \
190-
name& operator=(name&) = delete; \
187+
explicit name(const name&) = delete; \
188+
name& operator=(const name&) = delete; \
191189
};
192190

193191
/*

‎mfbt/Span.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class extent_type {
260260

261261
static_assert(Ext >= 0, "A fixed-size Span must be >= 0 in size.");
262262

263-
constexpr extent_type() {}
263+
constexpr extent_type() = default;
264264

265265
template <index_type Other>
266266
constexpr MOZ_IMPLICIT extent_type(extent_type<Other> ext) {

‎mfbt/ThreadSafeWeakPtr.h

+5-13
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,13 @@ class ThreadSafeWeakPtr {
258258
typedef typename T::ThreadSafeWeakReference ThreadSafeWeakReference;
259259

260260
public:
261-
ThreadSafeWeakPtr() {}
261+
ThreadSafeWeakPtr() = default;
262262

263-
ThreadSafeWeakPtr& operator=(const ThreadSafeWeakPtr& aOther) {
264-
mRef = aOther.mRef;
265-
return *this;
266-
}
267-
268-
ThreadSafeWeakPtr(const ThreadSafeWeakPtr& aOther) : mRef(aOther.mRef) {}
269-
270-
ThreadSafeWeakPtr& operator=(ThreadSafeWeakPtr&& aOther) {
271-
mRef = aOther.mRef.forget();
272-
return *this;
273-
}
263+
ThreadSafeWeakPtr& operator=(const ThreadSafeWeakPtr& aOther) = default;
264+
ThreadSafeWeakPtr(const ThreadSafeWeakPtr& aOther) = default;
274265

275-
ThreadSafeWeakPtr(ThreadSafeWeakPtr&& aOther) : mRef(aOther.mRef.forget()) {}
266+
ThreadSafeWeakPtr& operator=(ThreadSafeWeakPtr&& aOther) = default;
267+
ThreadSafeWeakPtr(ThreadSafeWeakPtr&& aOther) = default;
276268

277269
ThreadSafeWeakPtr& operator=(const RefPtr<T>& aOther) {
278270
if (aOther) {

‎mfbt/UniquePtr.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class UniquePtr<T[], D> {
474474
template <typename T>
475475
class DefaultDelete {
476476
public:
477-
constexpr DefaultDelete() {}
477+
constexpr DefaultDelete() = default;
478478

479479
template <typename U>
480480
MOZ_IMPLICIT DefaultDelete(
@@ -492,7 +492,7 @@ class DefaultDelete {
492492
template <typename T>
493493
class DefaultDelete<T[]> {
494494
public:
495-
constexpr DefaultDelete() {}
495+
constexpr DefaultDelete() = default;
496496

497497
void operator()(T* aPtr) const {
498498
static_assert(sizeof(T) > 0, "T must be complete");

‎mfbt/tests/TestRollingMean.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MyClass {
3232

3333
class RollingMeanSuite {
3434
public:
35-
RollingMeanSuite() {}
35+
RollingMeanSuite() = default;
3636

3737
void runTests() {
3838
testZero();

‎mfbt/tests/TestSPSCQueue.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace mozilla;
2323
template <typename T>
2424
class SequenceGenerator {
2525
public:
26-
SequenceGenerator() {}
26+
SequenceGenerator() = default;
2727
void Get(T* aElements, size_t aCount) {
2828
for (size_t i = 0; i < aCount; i++) {
2929
aElements[i] = static_cast<T>(mIndex);
@@ -40,7 +40,7 @@ class SequenceGenerator {
4040
template <typename T>
4141
class SequenceVerifier {
4242
public:
43-
SequenceVerifier() {}
43+
SequenceVerifier() = default;
4444
void Check(T* aElements, size_t aCount) {
4545
for (size_t i = 0; i < aCount; i++) {
4646
if (aElements[i] != static_cast<T>(mIndex)) {

‎mfbt/tests/TestTypeTraits.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct NE1 {
168168
};
169169
struct NE2 : virtual E1 {};
170170
struct NE3 : E2 {
171-
virtual ~NE3() {}
171+
virtual ~NE3() = default;
172172
};
173173
struct NE4 {
174174
virtual void f() {}
@@ -258,13 +258,13 @@ struct TrivialCtor1 {
258258
};
259259

260260
struct DefaultCtor0 {
261-
DefaultCtor0() {}
261+
DefaultCtor0() = default;
262262
};
263263
struct DefaultCtor1 {
264264
DefaultCtor1() = default;
265265
};
266266
struct DefaultCtor2 {
267-
DefaultCtor2() {}
267+
DefaultCtor2() = default;
268268
explicit DefaultCtor2(int) {}
269269
};
270270

@@ -276,7 +276,7 @@ struct NoDefaultCtor1 {
276276
};
277277

278278
class PrivateCtor0 {
279-
PrivateCtor0() {}
279+
PrivateCtor0() = default;
280280
};
281281
class PrivateCtor1 {
282282
PrivateCtor1() = default;

‎mfbt/tests/TestUniquePtr.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void TestDeleterType() {
7777
typedef int* Ptr;
7878
struct Deleter {
7979
typedef Ptr pointer;
80-
Deleter() {}
80+
Deleter() = default;
8181
void operator()(int* p) { delete p; }
8282
};
8383
UniquePtr<Ptr, Deleter> u(new int, Deleter());
@@ -216,7 +216,7 @@ static size_t FreeClassCounter = 0;
216216

217217
struct FreeClass {
218218
public:
219-
FreeClass() {}
219+
FreeClass() = default;
220220

221221
void operator()(int* aPtr) {
222222
FreeClassCounter++;
@@ -366,7 +366,7 @@ static bool TestFunctionReferenceDeleter() {
366366

367367
template <typename T>
368368
struct AppendNullptrTwice {
369-
AppendNullptrTwice() {}
369+
AppendNullptrTwice() = default;
370370

371371
bool operator()(Vector<T>& vec) {
372372
CHECK(vec.append(nullptr));
@@ -481,8 +481,8 @@ static bool TestArray() {
481481
}
482482

483483
struct Q {
484-
Q() {}
485-
Q(const Q&) {}
484+
Q() = default;
485+
Q(const Q&) = default;
486486

487487
Q(Q&, char) {}
488488

‎mfbt/tests/gtest/TestMozDbg.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ using namespace mozilla;
2424
struct Number {
2525
explicit Number(int aValue) : mValue(aValue) {}
2626

27-
Number(const Number& aOther) : mValue(aOther.mValue) {}
27+
Number(const Number& aOther) = default;
2828

2929
Number(Number&& aOther) : mValue(aOther.mValue) { aOther.mValue = 0; }
3030

31-
Number& operator=(const Number& aOther) {
32-
mValue = aOther.mValue;
33-
return *this;
34-
}
31+
Number& operator=(const Number& aOther) = default;
3532

3633
Number& operator=(Number&& aOther) {
3734
mValue = aOther.mValue;
@@ -53,10 +50,7 @@ struct MoveOnly {
5350

5451
MoveOnly(MoveOnly&& aOther) : mValue(aOther.mValue) { aOther.mValue = 0; }
5552

56-
MoveOnly& operator=(MoveOnly& aOther) {
57-
mValue = aOther.mValue;
58-
return *this;
59-
}
53+
MoveOnly& operator=(MoveOnly& aOther) = default;
6054

6155
MoveOnly& operator=(MoveOnly&& aOther) {
6256
mValue = aOther.mValue;

0 commit comments

Comments
 (0)
Failed to load comments.