Skip to content

Commit 7aa40f5

Browse files
committed
refactor: use C++11 default initializers
1 parent d5d40d5 commit 7aa40f5

39 files changed

+57
-88
lines changed

Diff for: src/bench/checkqueue.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
3030

3131
struct PrevectorJob {
3232
prevector<PREVECTOR_SIZE, uint8_t> p;
33-
PrevectorJob(){
34-
}
33+
PrevectorJob() = default;
3534
explicit PrevectorJob(FastRandomContext& insecure_rand){
3635
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
3736
}

Diff for: src/bench/prevector.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <bench/bench.h>
1111

1212
struct nontrivial_t {
13-
int x;
14-
nontrivial_t() :x(-1) {}
13+
int x{-1};
14+
nontrivial_t() = default;
1515
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
1616
};
1717
static_assert(!std::is_trivially_default_constructible<nontrivial_t>::value,

Diff for: src/bitcoin-cli.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ static int AppInitRPC(int argc, char* argv[])
180180
/** Reply structure for request_done to fill in */
181181
struct HTTPReply
182182
{
183-
HTTPReply(): status(0), error(-1) {}
183+
HTTPReply() = default;
184184

185-
int status;
186-
int error;
185+
int status{0};
186+
int error{-1};
187187
std::string body;
188188
};
189189

@@ -244,7 +244,7 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx)
244244
class BaseRequestHandler
245245
{
246246
public:
247-
virtual ~BaseRequestHandler() {}
247+
virtual ~BaseRequestHandler() = default;
248248
virtual UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) = 0;
249249
virtual UniValue ProcessReply(const UniValue &batch_in) = 0;
250250
};

Diff for: src/httpserver.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,16 @@ class WorkQueue
7373
Mutex cs;
7474
std::condition_variable cond GUARDED_BY(cs);
7575
std::deque<std::unique_ptr<WorkItem>> queue GUARDED_BY(cs);
76-
bool running GUARDED_BY(cs);
76+
bool running GUARDED_BY(cs){true};
7777
const size_t maxDepth;
7878

7979
public:
80-
explicit WorkQueue(size_t _maxDepth) : running(true),
81-
maxDepth(_maxDepth)
80+
explicit WorkQueue(size_t _maxDepth) : maxDepth(_maxDepth)
8281
{
8382
}
8483
/** Precondition: worker threads have all stopped (they have been joined).
8584
*/
86-
~WorkQueue()
87-
{
88-
}
85+
~WorkQueue() = default;
8986
/** Enqueue a work item */
9087
bool Enqueue(WorkItem* item) EXCLUSIVE_LOCKS_REQUIRED(!cs)
9188
{

Diff for: src/index/txindex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TxIndex::TxIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
5252
: m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
5353
{}
5454

55-
TxIndex::~TxIndex() {}
55+
TxIndex::~TxIndex() = default;
5656

5757
bool TxIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
5858
{

Diff for: src/net.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
26912691
class CNetCleanup
26922692
{
26932693
public:
2694-
CNetCleanup() {}
2694+
CNetCleanup() = default;
26952695

26962696
~CNetCleanup()
26972697
{

Diff for: src/netaddress.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool CNetAddr::SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t addre
9898
*
9999
* @note This address is considered invalid by CNetAddr::IsValid()
100100
*/
101-
CNetAddr::CNetAddr() {}
101+
CNetAddr::CNetAddr() = default;
102102

103103
void CNetAddr::SetIP(const CNetAddr& ipIn)
104104
{

Diff for: src/node/context.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
#include <validation.h>
1717

1818
namespace node {
19-
NodeContext::NodeContext() {}
20-
NodeContext::~NodeContext() {}
19+
NodeContext::NodeContext() = default;
20+
NodeContext::~NodeContext() = default;
2121
} // namespace node

Diff for: src/policy/fees.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,7 @@ CBlockPolicyEstimator::CBlockPolicyEstimator()
537537
}
538538
}
539539

540-
CBlockPolicyEstimator::~CBlockPolicyEstimator()
541-
{
542-
}
540+
CBlockPolicyEstimator::~CBlockPolicyEstimator() = default;
543541

544542
void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate)
545543
{

Diff for: src/qt/addresstablemodel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct AddressTableEntry
3030
QString label;
3131
QString address;
3232

33-
AddressTableEntry() {}
33+
AddressTableEntry() = default;
3434
AddressTableEntry(Type _type, const QString &_label, const QString &_address):
3535
type(_type), label(_label), address(_address) {}
3636
};

Diff for: src/qt/bantablemodel.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ BanTableModel::BanTableModel(interfaces::Node& node, QObject* parent) :
8989
refresh();
9090
}
9191

92-
BanTableModel::~BanTableModel()
93-
{
94-
// Intentionally left empty
95-
}
92+
BanTableModel::~BanTableModel() = default;
9693

9794
int BanTableModel::rowCount(const QModelIndex &parent) const
9895
{

Diff for: src/qt/notificator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Notificator::~Notificator()
7171
class FreedesktopImage
7272
{
7373
public:
74-
FreedesktopImage() {}
74+
FreedesktopImage() = default;
7575
explicit FreedesktopImage(const QImage &img);
7676

7777
// Image to variant that can be marshalled over DBus

Diff for: src/qt/overviewpage.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class TxViewDelegate : public QAbstractItemDelegate
3535
Q_OBJECT
3636
public:
3737
explicit TxViewDelegate(const PlatformStyle* _platformStyle, QObject* parent = nullptr)
38-
: QAbstractItemDelegate(parent), unit(BitcoinUnit::BTC),
39-
platformStyle(_platformStyle)
38+
: QAbstractItemDelegate(parent), platformStyle(_platformStyle)
4039
{
4140
connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged);
4241
}
@@ -125,7 +124,7 @@ class TxViewDelegate : public QAbstractItemDelegate
125124
return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE};
126125
}
127126

128-
BitcoinUnit unit;
127+
BitcoinUnit unit{BitcoinUnit::BTC};
129128

130129
Q_SIGNALS:
131130
//! An intermediate signal for emitting from the `paint() const` member function.

Diff for: src/qt/paymentserver.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
158158
}
159159
}
160160

161-
PaymentServer::~PaymentServer()
162-
{
163-
}
161+
PaymentServer::~PaymentServer() = default;
164162

165163
//
166164
// OSX-specific way of handling bitcoin: URIs

Diff for: src/qt/peertablemodel.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ PeerTableModel::PeerTableModel(interfaces::Node& node, QObject* parent) :
2828
refresh();
2929
}
3030

31-
PeerTableModel::~PeerTableModel()
32-
{
33-
// Intentionally left empty
34-
}
31+
PeerTableModel::~PeerTableModel() = default;
3532

3633
void PeerTableModel::startAutoRefresh()
3734
{

Diff for: src/qt/recentrequeststablemodel.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
3434
connect(walletModel->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &RecentRequestsTableModel::updateDisplayUnit);
3535
}
3636

37-
RecentRequestsTableModel::~RecentRequestsTableModel()
38-
{
39-
/* Intentionally left empty */
40-
}
37+
RecentRequestsTableModel::~RecentRequestsTableModel() = default;
4138

4239
int RecentRequestsTableModel::rowCount(const QModelIndex &parent) const
4340
{

Diff for: src/qt/rpcconsole.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class QtRPCTimerBase: public QObject, public RPCTimerBase
120120
connect(&timer, &QTimer::timeout, [this]{ func(); });
121121
timer.start(millis);
122122
}
123-
~QtRPCTimerBase() {}
123+
~QtRPCTimerBase() = default;
124124
private:
125125
QTimer timer;
126126
std::function<void()> func;
@@ -129,7 +129,7 @@ class QtRPCTimerBase: public QObject, public RPCTimerBase
129129
class QtRPCTimerInterface: public RPCTimerInterface
130130
{
131131
public:
132-
~QtRPCTimerInterface() {}
132+
~QtRPCTimerInterface() = default;
133133
const char *Name() override { return "Qt"; }
134134
RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis) override
135135
{

Diff for: src/qt/transactiontablemodel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct TxLessThan
6262
struct TransactionNotification
6363
{
6464
public:
65-
TransactionNotification() {}
65+
TransactionNotification() = default;
6666
TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction):
6767
hash(_hash), status(_status), showTransaction(_showTransaction) {}
6868

Diff for: src/qt/walletframe.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, QWidget* parent)
5555
walletStack->addWidget(no_wallet_group);
5656
}
5757

58-
WalletFrame::~WalletFrame()
59-
{
60-
}
58+
WalletFrame::~WalletFrame() = default;
6159

6260
void WalletFrame::setClientModel(ClientModel *_clientModel)
6361
{

Diff for: src/qt/walletview.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platform
111111
connect(walletModel, &WalletModel::showProgress, this, &WalletView::showProgress);
112112
}
113113

114-
WalletView::~WalletView()
115-
{
116-
}
114+
WalletView::~WalletView() = default;
117115

118116
void WalletView::setClientModel(ClientModel *_clientModel)
119117
{

Diff for: src/random.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,7 @@ class RNGState {
370370
InitHardwareRand();
371371
}
372372

373-
~RNGState()
374-
{
375-
}
373+
~RNGState() = default;
376374

377375
void AddEvent(uint32_t event_info) noexcept EXCLUSIVE_LOCKS_REQUIRED(!m_events_mutex)
378376
{

Diff for: src/rpc/blockchain.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1948,9 +1948,9 @@ static std::atomic<bool> g_should_abort_scan;
19481948
class CoinsViewScanReserver
19491949
{
19501950
private:
1951-
bool m_could_reserve;
1951+
bool m_could_reserve{false};
19521952
public:
1953-
explicit CoinsViewScanReserver() : m_could_reserve(false) {}
1953+
explicit CoinsViewScanReserver() = default;
19541954

19551955
bool reserve() {
19561956
CHECK_NONFATAL(!m_could_reserve);

Diff for: src/rpc/mining.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -930,10 +930,10 @@ class submitblock_StateCatcher final : public CValidationInterface
930930
{
931931
public:
932932
uint256 hash;
933-
bool found;
933+
bool found{false};
934934
BlockValidationState state;
935935

936-
explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {}
936+
explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), state() {}
937937

938938
protected:
939939
void BlockChecked(const CBlock& block, const BlockValidationState& stateIn) override {

Diff for: src/rpc/util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vecto
267267
class DescribeAddressVisitor
268268
{
269269
public:
270-
explicit DescribeAddressVisitor() {}
270+
explicit DescribeAddressVisitor() = default;
271271

272272
UniValue operator()(const CNoDestination& dest) const
273273
{

Diff for: src/scheduler.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
#include <functional>
1313
#include <utility>
1414

15-
CScheduler::CScheduler()
16-
{
17-
}
15+
CScheduler::CScheduler() = default;
1816

1917
CScheduler::~CScheduler()
2018
{

Diff for: src/script/sign.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ namespace {
563563
class DummySignatureChecker final : public BaseSignatureChecker
564564
{
565565
public:
566-
DummySignatureChecker() {}
566+
DummySignatureChecker() = default;
567567
bool CheckECDSASignature(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override { return true; }
568568
bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror) const override { return true; }
569569
};

Diff for: src/support/lockedpool.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ LockedPool::LockedPool(std::unique_ptr<LockedPageAllocator> allocator_in, Lockin
282282
{
283283
}
284284

285-
LockedPool::~LockedPool()
286-
{
287-
}
285+
LockedPool::~LockedPool() = default;
286+
288287
void* LockedPool::alloc(size_t size)
289288
{
290289
std::lock_guard<std::mutex> lock(mutex);

Diff for: src/test/checkqueue_tests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct MemoryCheck {
9595
{
9696
return true;
9797
}
98-
MemoryCheck(){};
98+
MemoryCheck() = default;
9999
MemoryCheck(const MemoryCheck& x)
100100
{
101101
// We have to do this to make sure that destructor calls are paired
@@ -129,7 +129,7 @@ struct FrozenCleanupCheck {
129129
{
130130
return true;
131131
}
132-
FrozenCleanupCheck() {}
132+
FrozenCleanupCheck() = default;
133133
~FrozenCleanupCheck()
134134
{
135135
if (should_freeze) {

Diff for: src/test/dbwrapper_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ struct StringContentsSerializer {
321321
// Used to make two serialized objects the same while letting them have different lengths
322322
// This is a terrible idea
323323
std::string str;
324-
StringContentsSerializer() {}
324+
StringContentsSerializer() = default;
325325
explicit StringContentsSerializer(const std::string& inp) : str(inp) {}
326326

327327
StringContentsSerializer& operator+=(const std::string& s) {

Diff for: src/test/fuzz/signature_checker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FuzzedSignatureChecker : public BaseSignatureChecker
4949
return m_fuzzed_data_provider.ConsumeBool();
5050
}
5151

52-
virtual ~FuzzedSignatureChecker() {}
52+
virtual ~FuzzedSignatureChecker() = default;
5353
};
5454
} // namespace
5555

Diff for: src/test/script_tests.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ class TestBuilder
257257
CScriptWitness scriptWitness;
258258
CTransactionRef creditTx;
259259
CMutableTransaction spendTx;
260-
bool havePush;
260+
bool havePush{false};
261261
std::vector<unsigned char> push;
262262
std::string comment;
263263
uint32_t flags;
264-
int scriptError;
264+
int scriptError{SCRIPT_ERR_OK};
265265
CAmount nValue;
266266

267267
void DoPush()
@@ -280,7 +280,7 @@ class TestBuilder
280280
}
281281

282282
public:
283-
TestBuilder(const CScript& script_, const std::string& comment_, uint32_t flags_, bool P2SH = false, WitnessMode wm = WitnessMode::NONE, int witnessversion = 0, CAmount nValue_ = 0) : script(script_), havePush(false), comment(comment_), flags(flags_), scriptError(SCRIPT_ERR_OK), nValue(nValue_)
283+
TestBuilder(const CScript& script_, const std::string& comment_, uint32_t flags_, bool P2SH = false, WitnessMode wm = WitnessMode::NONE, int witnessversion = 0, CAmount nValue_ = 0) : script(script_), comment(comment_), flags(flags_), nValue(nValue_)
284284
{
285285
CScript scriptPubKey = script;
286286
if (wm == WitnessMode::PKH) {

Diff for: src/test/util_tests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2450,9 +2450,9 @@ struct Tracker
24502450
//! Points to the original object (possibly itself) we moved/copied from
24512451
const Tracker* origin;
24522452
//! How many copies where involved between the original object and this one (moves are not counted)
2453-
int copies;
2453+
int copies{0};
24542454

2455-
Tracker() noexcept : origin(this), copies(0) {}
2455+
Tracker() noexcept : origin(this) {}
24562456
Tracker(const Tracker& t) noexcept : origin(t.origin), copies(t.copies + 1) {}
24572457
Tracker(Tracker&& t) noexcept : origin(t.origin), copies(t.copies) {}
24582458
Tracker& operator=(const Tracker& t) noexcept

0 commit comments

Comments
 (0)