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 {
prevector<PREVECTOR_SIZE, uint8_t> p;
PrevectorJob(){
}
PrevectorJob() = default;
explicit PrevectorJob(FastRandomContext& insecure_rand){
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
}

View file

@ -10,8 +10,8 @@
#include <bench/bench.h>
struct nontrivial_t {
int x;
nontrivial_t() :x(-1) {}
int x{-1};
nontrivial_t() = default;
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
};
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 */
struct HTTPReply
{
HTTPReply(): status(0), error(-1) {}
HTTPReply() = default;
int status;
int error;
int status{0};
int error{-1};
std::string body;
};
@ -244,7 +244,7 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx)
class BaseRequestHandler
{
public:
virtual ~BaseRequestHandler() {}
virtual ~BaseRequestHandler() = default;
virtual UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) = 0;
virtual UniValue ProcessReply(const UniValue &batch_in) = 0;
};

View file

@ -73,19 +73,16 @@ private:
Mutex cs;
std::condition_variable cond 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;
public:
explicit WorkQueue(size_t _maxDepth) : running(true),
maxDepth(_maxDepth)
explicit WorkQueue(size_t _maxDepth) : maxDepth(_maxDepth)
{
}
/** Precondition: worker threads have all stopped (they have been joined).
*/
~WorkQueue()
{
}
~WorkQueue() = default;
/** Enqueue a work item */
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))
{}
TxIndex::~TxIndex() {}
TxIndex::~TxIndex() = default;
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
{
public:
CNetCleanup() {}
CNetCleanup() = default;
~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()
*/
CNetAddr::CNetAddr() {}
CNetAddr::CNetAddr() = default;
void CNetAddr::SetIP(const CNetAddr& ipIn)
{

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -35,8 +35,7 @@ class TxViewDelegate : public QAbstractItemDelegate
Q_OBJECT
public:
explicit TxViewDelegate(const PlatformStyle* _platformStyle, QObject* parent = nullptr)
: QAbstractItemDelegate(parent), unit(BitcoinUnit::BTC),
platformStyle(_platformStyle)
: QAbstractItemDelegate(parent), platformStyle(_platformStyle)
{
connect(this, &TxViewDelegate::width_changed, this, &TxViewDelegate::sizeHintChanged);
}
@ -125,7 +124,7 @@ public:
return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE};
}
BitcoinUnit unit;
BitcoinUnit unit{BitcoinUnit::BTC};
Q_SIGNALS:
//! 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

View file

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

View file

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

View file

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

View file

@ -62,7 +62,7 @@ struct TxLessThan
struct TransactionNotification
{
public:
TransactionNotification() {}
TransactionNotification() = default;
TransactionNotification(uint256 _hash, ChangeType _status, bool _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);
}
WalletFrame::~WalletFrame()
{
}
WalletFrame::~WalletFrame() = default;
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);
}
WalletView::~WalletView()
{
}
WalletView::~WalletView() = default;
void WalletView::setClientModel(ClientModel *_clientModel)
{

View file

@ -370,9 +370,7 @@ public:
InitHardwareRand();
}
~RNGState()
{
}
~RNGState() = default;
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
{
private:
bool m_could_reserve;
bool m_could_reserve{false};
public:
explicit CoinsViewScanReserver() : m_could_reserve(false) {}
explicit CoinsViewScanReserver() = default;
bool reserve() {
CHECK_NONFATAL(!m_could_reserve);

View file

@ -930,10 +930,10 @@ class submitblock_StateCatcher final : public CValidationInterface
{
public:
uint256 hash;
bool found;
bool found{false};
BlockValidationState state;
explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {}
explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), state() {}
protected:
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
{
public:
explicit DescribeAddressVisitor() {}
explicit DescribeAddressVisitor() = default;
UniValue operator()(const CNoDestination& dest) const
{

View file

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

View file

@ -563,7 +563,7 @@ namespace {
class DummySignatureChecker final : public BaseSignatureChecker
{
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 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)
{
std::lock_guard<std::mutex> lock(mutex);

View file

@ -95,7 +95,7 @@ struct MemoryCheck {
{
return true;
}
MemoryCheck(){};
MemoryCheck() = default;
MemoryCheck(const MemoryCheck& x)
{
// We have to do this to make sure that destructor calls are paired
@ -129,7 +129,7 @@ struct FrozenCleanupCheck {
{
return true;
}
FrozenCleanupCheck() {}
FrozenCleanupCheck() = default;
~FrozenCleanupCheck()
{
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
// This is a terrible idea
std::string str;
StringContentsSerializer() {}
StringContentsSerializer() = default;
explicit StringContentsSerializer(const std::string& inp) : str(inp) {}
StringContentsSerializer& operator+=(const std::string& s) {

View file

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

View file

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

View file

@ -2450,9 +2450,9 @@ struct Tracker
//! Points to the original object (possibly itself) we moved/copied from
const Tracker* origin;
//! 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(Tracker&& t) noexcept : origin(t.origin), copies(t.copies) {}
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):
base(_base),
m_tor_control_center(tor_control_center), conn(base), reconnect(true), reconnect_ev(nullptr),
reconnect_timeout(RECONNECT_TIMEOUT_START),
m_tor_control_center(tor_control_center), conn(base), reconnect(true), reconnect_timeout(RECONNECT_TIMEOUT_START),
m_target(target)
{
reconnect_ev = event_new(base, -1, 0, reconnect_cb, this);

View file

@ -207,7 +207,7 @@ public:
// cache warmup on instantiation.
CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256&hashBlockIn):
CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {}
~CCoinsViewDBCursor() {}
~CCoinsViewDBCursor() = default;
bool GetKey(COutPoint &key) 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
// #include class definitions for all members.
// For example, m_settings has an internal dependency on univalue.
ArgsManager::ArgsManager() {}
ArgsManager::~ArgsManager() {}
ArgsManager::ArgsManager() = default;
ArgsManager::~ArgsManager() = default;
const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
{

View file

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

View file

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

View file

@ -63,9 +63,7 @@ struct tallyitem
int nConf{std::numeric_limits<int>::max()};
std::vector<uint256> txids;
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)

View file

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