0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

refactor: use C++11 default initializers

This commit is contained in:
fanquake 2022-05-11 16:02:15 +01:00
parent d5d40d59f8
commit 7aa40f5563
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
39 changed files with 57 additions and 88 deletions

View file

@ -30,8 +30,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
struct PrevectorJob { struct PrevectorJob {
prevector<PREVECTOR_SIZE, uint8_t> p; prevector<PREVECTOR_SIZE, uint8_t> p;
PrevectorJob(){ PrevectorJob() = default;
}
explicit PrevectorJob(FastRandomContext& insecure_rand){ explicit PrevectorJob(FastRandomContext& insecure_rand){
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2)); p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
} }

View file

@ -10,8 +10,8 @@
#include <bench/bench.h> #include <bench/bench.h>
struct nontrivial_t { struct nontrivial_t {
int x; int x{-1};
nontrivial_t() :x(-1) {} nontrivial_t() = default;
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); } SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
}; };
static_assert(!std::is_trivially_default_constructible<nontrivial_t>::value, static_assert(!std::is_trivially_default_constructible<nontrivial_t>::value,

View file

@ -180,10 +180,10 @@ static int AppInitRPC(int argc, char* argv[])
/** Reply structure for request_done to fill in */ /** Reply structure for request_done to fill in */
struct HTTPReply struct HTTPReply
{ {
HTTPReply(): status(0), error(-1) {} HTTPReply() = default;
int status; int status{0};
int error; int error{-1};
std::string body; std::string body;
}; };
@ -244,7 +244,7 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx)
class BaseRequestHandler class BaseRequestHandler
{ {
public: public:
virtual ~BaseRequestHandler() {} virtual ~BaseRequestHandler() = default;
virtual UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) = 0; virtual UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) = 0;
virtual UniValue ProcessReply(const UniValue &batch_in) = 0; virtual UniValue ProcessReply(const UniValue &batch_in) = 0;
}; };

View file

@ -73,19 +73,16 @@ private:
Mutex cs; Mutex cs;
std::condition_variable cond GUARDED_BY(cs); std::condition_variable cond GUARDED_BY(cs);
std::deque<std::unique_ptr<WorkItem>> queue GUARDED_BY(cs); std::deque<std::unique_ptr<WorkItem>> queue GUARDED_BY(cs);
bool running GUARDED_BY(cs); bool running GUARDED_BY(cs){true};
const size_t maxDepth; const size_t maxDepth;
public: public:
explicit WorkQueue(size_t _maxDepth) : running(true), explicit WorkQueue(size_t _maxDepth) : maxDepth(_maxDepth)
maxDepth(_maxDepth)
{ {
} }
/** Precondition: worker threads have all stopped (they have been joined). /** Precondition: worker threads have all stopped (they have been joined).
*/ */
~WorkQueue() ~WorkQueue() = default;
{
}
/** Enqueue a work item */ /** Enqueue a work item */
bool Enqueue(WorkItem* item) EXCLUSIVE_LOCKS_REQUIRED(!cs) bool Enqueue(WorkItem* item) EXCLUSIVE_LOCKS_REQUIRED(!cs)
{ {

View file

@ -52,7 +52,7 @@ TxIndex::TxIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
: m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe)) : m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
{} {}
TxIndex::~TxIndex() {} TxIndex::~TxIndex() = default;
bool TxIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex) bool TxIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
{ {

View file

@ -2691,7 +2691,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
class CNetCleanup class CNetCleanup
{ {
public: public:
CNetCleanup() {} CNetCleanup() = default;
~CNetCleanup() ~CNetCleanup()
{ {

View file

@ -98,7 +98,7 @@ bool CNetAddr::SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t addre
* *
* @note This address is considered invalid by CNetAddr::IsValid() * @note This address is considered invalid by CNetAddr::IsValid()
*/ */
CNetAddr::CNetAddr() {} CNetAddr::CNetAddr() = default;
void CNetAddr::SetIP(const CNetAddr& ipIn) void CNetAddr::SetIP(const CNetAddr& ipIn)
{ {

View file

@ -16,6 +16,6 @@
#include <validation.h> #include <validation.h>
namespace node { namespace node {
NodeContext::NodeContext() {} NodeContext::NodeContext() = default;
NodeContext::~NodeContext() {} NodeContext::~NodeContext() = default;
} // namespace node } // namespace node

View file

@ -537,9 +537,7 @@ CBlockPolicyEstimator::CBlockPolicyEstimator()
} }
} }
CBlockPolicyEstimator::~CBlockPolicyEstimator() CBlockPolicyEstimator::~CBlockPolicyEstimator() = default;
{
}
void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate) void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate)
{ {

View file

@ -30,7 +30,7 @@ struct AddressTableEntry
QString label; QString label;
QString address; QString address;
AddressTableEntry() {} AddressTableEntry() = default;
AddressTableEntry(Type _type, const QString &_label, const QString &_address): AddressTableEntry(Type _type, const QString &_label, const QString &_address):
type(_type), label(_label), address(_address) {} type(_type), label(_label), address(_address) {}
}; };

View file

@ -89,10 +89,7 @@ BanTableModel::BanTableModel(interfaces::Node& node, QObject* parent) :
refresh(); refresh();
} }
BanTableModel::~BanTableModel() BanTableModel::~BanTableModel() = default;
{
// Intentionally left empty
}
int BanTableModel::rowCount(const QModelIndex &parent) const int BanTableModel::rowCount(const QModelIndex &parent) const
{ {

View file

@ -71,7 +71,7 @@ Notificator::~Notificator()
class FreedesktopImage class FreedesktopImage
{ {
public: public:
FreedesktopImage() {} FreedesktopImage() = default;
explicit FreedesktopImage(const QImage &img); explicit FreedesktopImage(const QImage &img);
// Image to variant that can be marshalled over DBus // Image to variant that can be marshalled over DBus

View file

@ -35,8 +35,7 @@ class TxViewDelegate : public QAbstractItemDelegate
Q_OBJECT Q_OBJECT
public: public:
explicit TxViewDelegate(const PlatformStyle* _platformStyle, QObject* parent = nullptr) explicit TxViewDelegate(const PlatformStyle* _platformStyle, QObject* parent = nullptr)
: QAbstractItemDelegate(parent), unit(BitcoinUnit::BTC), : QAbstractItemDelegate(parent), platformStyle(_platformStyle)
platformStyle(_platformStyle)
{ {
connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged); connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged);
} }
@ -125,7 +124,7 @@ public:
return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE}; return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE};
} }
BitcoinUnit unit; BitcoinUnit unit{BitcoinUnit::BTC};
Q_SIGNALS: Q_SIGNALS:
//! An intermediate signal for emitting from the `paint() const` member function. //! An intermediate signal for emitting from the `paint() const` member function.

View file

@ -158,9 +158,7 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
} }
} }
PaymentServer::~PaymentServer() PaymentServer::~PaymentServer() = default;
{
}
// //
// OSX-specific way of handling bitcoin: URIs // OSX-specific way of handling bitcoin: URIs

View file

@ -28,10 +28,7 @@ PeerTableModel::PeerTableModel(interfaces::Node& node, QObject* parent) :
refresh(); refresh();
} }
PeerTableModel::~PeerTableModel() PeerTableModel::~PeerTableModel() = default;
{
// Intentionally left empty
}
void PeerTableModel::startAutoRefresh() void PeerTableModel::startAutoRefresh()
{ {

View file

@ -34,10 +34,7 @@ RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
connect(walletModel->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &RecentRequestsTableModel::updateDisplayUnit); connect(walletModel->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &RecentRequestsTableModel::updateDisplayUnit);
} }
RecentRequestsTableModel::~RecentRequestsTableModel() RecentRequestsTableModel::~RecentRequestsTableModel() = default;
{
/* Intentionally left empty */
}
int RecentRequestsTableModel::rowCount(const QModelIndex &parent) const int RecentRequestsTableModel::rowCount(const QModelIndex &parent) const
{ {

View file

@ -120,7 +120,7 @@ public:
connect(&timer, &QTimer::timeout, [this]{ func(); }); connect(&timer, &QTimer::timeout, [this]{ func(); });
timer.start(millis); timer.start(millis);
} }
~QtRPCTimerBase() {} ~QtRPCTimerBase() = default;
private: private:
QTimer timer; QTimer timer;
std::function<void()> func; std::function<void()> func;
@ -129,7 +129,7 @@ private:
class QtRPCTimerInterface: public RPCTimerInterface class QtRPCTimerInterface: public RPCTimerInterface
{ {
public: public:
~QtRPCTimerInterface() {} ~QtRPCTimerInterface() = default;
const char *Name() override { return "Qt"; } const char *Name() override { return "Qt"; }
RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis) override RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis) override
{ {

View file

@ -62,7 +62,7 @@ struct TxLessThan
struct TransactionNotification struct TransactionNotification
{ {
public: public:
TransactionNotification() {} TransactionNotification() = default;
TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction): TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction):
hash(_hash), status(_status), showTransaction(_showTransaction) {} hash(_hash), status(_status), showTransaction(_showTransaction) {}

View file

@ -55,9 +55,7 @@ WalletFrame::WalletFrame(const PlatformStyle* _platformStyle, QWidget* parent)
walletStack->addWidget(no_wallet_group); walletStack->addWidget(no_wallet_group);
} }
WalletFrame::~WalletFrame() WalletFrame::~WalletFrame() = default;
{
}
void WalletFrame::setClientModel(ClientModel *_clientModel) void WalletFrame::setClientModel(ClientModel *_clientModel)
{ {

View file

@ -111,9 +111,7 @@ WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platform
connect(walletModel, &WalletModel::showProgress, this, &WalletView::showProgress); connect(walletModel, &WalletModel::showProgress, this, &WalletView::showProgress);
} }
WalletView::~WalletView() WalletView::~WalletView() = default;
{
}
void WalletView::setClientModel(ClientModel *_clientModel) void WalletView::setClientModel(ClientModel *_clientModel)
{ {

View file

@ -370,9 +370,7 @@ public:
InitHardwareRand(); InitHardwareRand();
} }
~RNGState() ~RNGState() = default;
{
}
void AddEvent(uint32_t event_info) noexcept EXCLUSIVE_LOCKS_REQUIRED(!m_events_mutex) void AddEvent(uint32_t event_info) noexcept EXCLUSIVE_LOCKS_REQUIRED(!m_events_mutex)
{ {

View file

@ -1948,9 +1948,9 @@ static std::atomic<bool> g_should_abort_scan;
class CoinsViewScanReserver class CoinsViewScanReserver
{ {
private: private:
bool m_could_reserve; bool m_could_reserve{false};
public: public:
explicit CoinsViewScanReserver() : m_could_reserve(false) {} explicit CoinsViewScanReserver() = default;
bool reserve() { bool reserve() {
CHECK_NONFATAL(!m_could_reserve); CHECK_NONFATAL(!m_could_reserve);

View file

@ -930,10 +930,10 @@ class submitblock_StateCatcher final : public CValidationInterface
{ {
public: public:
uint256 hash; uint256 hash;
bool found; bool found{false};
BlockValidationState state; BlockValidationState state;
explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {} explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), state() {}
protected: protected:
void BlockChecked(const CBlock& block, const BlockValidationState& stateIn) override { void BlockChecked(const CBlock& block, const BlockValidationState& stateIn) override {

View file

@ -267,7 +267,7 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vecto
class DescribeAddressVisitor class DescribeAddressVisitor
{ {
public: public:
explicit DescribeAddressVisitor() {} explicit DescribeAddressVisitor() = default;
UniValue operator()(const CNoDestination& dest) const UniValue operator()(const CNoDestination& dest) const
{ {

View file

@ -12,9 +12,7 @@
#include <functional> #include <functional>
#include <utility> #include <utility>
CScheduler::CScheduler() CScheduler::CScheduler() = default;
{
}
CScheduler::~CScheduler() CScheduler::~CScheduler()
{ {

View file

@ -563,7 +563,7 @@ namespace {
class DummySignatureChecker final : public BaseSignatureChecker class DummySignatureChecker final : public BaseSignatureChecker
{ {
public: public:
DummySignatureChecker() {} DummySignatureChecker() = default;
bool CheckECDSASignature(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override { return true; } bool CheckECDSASignature(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override { return true; }
bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror) const override { return true; } bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror) const override { return true; }
}; };

View file

@ -282,9 +282,8 @@ LockedPool::LockedPool(std::unique_ptr<LockedPageAllocator> allocator_in, Lockin
{ {
} }
LockedPool::~LockedPool() LockedPool::~LockedPool() = default;
{
}
void* LockedPool::alloc(size_t size) void* LockedPool::alloc(size_t size)
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);

View file

@ -95,7 +95,7 @@ struct MemoryCheck {
{ {
return true; return true;
} }
MemoryCheck(){}; MemoryCheck() = default;
MemoryCheck(const MemoryCheck& x) MemoryCheck(const MemoryCheck& x)
{ {
// We have to do this to make sure that destructor calls are paired // We have to do this to make sure that destructor calls are paired
@ -129,7 +129,7 @@ struct FrozenCleanupCheck {
{ {
return true; return true;
} }
FrozenCleanupCheck() {} FrozenCleanupCheck() = default;
~FrozenCleanupCheck() ~FrozenCleanupCheck()
{ {
if (should_freeze) { if (should_freeze) {

View file

@ -321,7 +321,7 @@ struct StringContentsSerializer {
// Used to make two serialized objects the same while letting them have different lengths // Used to make two serialized objects the same while letting them have different lengths
// This is a terrible idea // This is a terrible idea
std::string str; std::string str;
StringContentsSerializer() {} StringContentsSerializer() = default;
explicit StringContentsSerializer(const std::string& inp) : str(inp) {} explicit StringContentsSerializer(const std::string& inp) : str(inp) {}
StringContentsSerializer& operator+=(const std::string& s) { StringContentsSerializer& operator+=(const std::string& s) {

View file

@ -49,7 +49,7 @@ public:
return m_fuzzed_data_provider.ConsumeBool(); return m_fuzzed_data_provider.ConsumeBool();
} }
virtual ~FuzzedSignatureChecker() {} virtual ~FuzzedSignatureChecker() = default;
}; };
} // namespace } // namespace

View file

@ -257,11 +257,11 @@ private:
CScriptWitness scriptWitness; CScriptWitness scriptWitness;
CTransactionRef creditTx; CTransactionRef creditTx;
CMutableTransaction spendTx; CMutableTransaction spendTx;
bool havePush; bool havePush{false};
std::vector<unsigned char> push; std::vector<unsigned char> push;
std::string comment; std::string comment;
uint32_t flags; uint32_t flags;
int scriptError; int scriptError{SCRIPT_ERR_OK};
CAmount nValue; CAmount nValue;
void DoPush() void DoPush()
@ -280,7 +280,7 @@ private:
} }
public: public:
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_) 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_)
{ {
CScript scriptPubKey = script; CScript scriptPubKey = script;
if (wm == WitnessMode::PKH) { if (wm == WitnessMode::PKH) {

View file

@ -2450,9 +2450,9 @@ struct Tracker
//! Points to the original object (possibly itself) we moved/copied from //! Points to the original object (possibly itself) we moved/copied from
const Tracker* origin; const Tracker* origin;
//! How many copies where involved between the original object and this one (moves are not counted) //! How many copies where involved between the original object and this one (moves are not counted)
int copies; int copies{0};
Tracker() noexcept : origin(this), copies(0) {} Tracker() noexcept : origin(this) {}
Tracker(const Tracker& t) noexcept : origin(t.origin), copies(t.copies + 1) {} Tracker(const Tracker& t) noexcept : origin(t.origin), copies(t.copies + 1) {}
Tracker(Tracker&& t) noexcept : origin(t.origin), copies(t.copies) {} Tracker(Tracker&& t) noexcept : origin(t.origin), copies(t.copies) {}
Tracker& operator=(const Tracker& t) noexcept Tracker& operator=(const Tracker& t) noexcept

View file

@ -304,8 +304,7 @@ std::map<std::string,std::string> ParseTorReplyMapping(const std::string &s)
TorController::TorController(struct event_base* _base, const std::string& tor_control_center, const CService& target): TorController::TorController(struct event_base* _base, const std::string& tor_control_center, const CService& target):
base(_base), base(_base),
m_tor_control_center(tor_control_center), conn(base), reconnect(true), reconnect_ev(nullptr), m_tor_control_center(tor_control_center), conn(base), reconnect(true), reconnect_timeout(RECONNECT_TIMEOUT_START),
reconnect_timeout(RECONNECT_TIMEOUT_START),
m_target(target) m_target(target)
{ {
reconnect_ev = event_new(base, -1, 0, reconnect_cb, this); reconnect_ev = event_new(base, -1, 0, reconnect_cb, this);

View file

@ -207,7 +207,7 @@ public:
// cache warmup on instantiation. // cache warmup on instantiation.
CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256&hashBlockIn): CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256&hashBlockIn):
CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {} CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {}
~CCoinsViewDBCursor() {} ~CCoinsViewDBCursor() = default;
bool GetKey(COutPoint &key) const override; bool GetKey(COutPoint &key) const override;
bool GetValue(Coin &coin) const override; bool GetValue(Coin &coin) const override;

View file

@ -258,8 +258,8 @@ static std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, con
// Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to // Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to
// #include class definitions for all members. // #include class definitions for all members.
// For example, m_settings has an internal dependency on univalue. // For example, m_settings has an internal dependency on univalue.
ArgsManager::ArgsManager() {} ArgsManager::ArgsManager() = default;
ArgsManager::~ArgsManager() {} ArgsManager::~ArgsManager() = default;
const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
{ {

View file

@ -2654,7 +2654,7 @@ static int64_t nTimePostConnect = 0;
struct PerBlockConnectTrace { struct PerBlockConnectTrace {
CBlockIndex* pindex = nullptr; CBlockIndex* pindex = nullptr;
std::shared_ptr<const CBlock> pblock; std::shared_ptr<const CBlock> pblock;
PerBlockConnectTrace() {} PerBlockConnectTrace() = default;
}; };
/** /**
* Used to track blocks whose transactions were applied to the UTXO state as a * Used to track blocks whose transactions were applied to the UTXO state as a

View file

@ -5,6 +5,6 @@
#include <wallet/context.h> #include <wallet/context.h>
namespace wallet { namespace wallet {
WalletContext::WalletContext() {} WalletContext::WalletContext() = default;
WalletContext::~WalletContext() {} WalletContext::~WalletContext() = default;
} // namespace wallet } // namespace wallet

View file

@ -63,9 +63,7 @@ struct tallyitem
int nConf{std::numeric_limits<int>::max()}; int nConf{std::numeric_limits<int>::max()};
std::vector<uint256> txids; std::vector<uint256> txids;
bool fIsWatchonly{false}; bool fIsWatchonly{false};
tallyitem() tallyitem() = default;
{
}
}; };
static UniValue ListReceived(const CWallet& wallet, const UniValue& params, const bool by_label, const bool include_immature_coinbase) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) static UniValue ListReceived(const CWallet& wallet, const UniValue& params, const bool by_label, const bool include_immature_coinbase) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)

View file

@ -314,8 +314,7 @@ public:
std::map<uint160, CHDChain> m_hd_chains; std::map<uint160, CHDChain> m_hd_chains;
bool tx_corrupt{false}; bool tx_corrupt{false};
CWalletScanState() { CWalletScanState() = default;
}
}; };
static bool static bool