clang-tidy: Fix `modernize-use-default-member-init` in headers

See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-default-member-init.html
pull/26705/head
Hennadii Stepanov 1 year ago
parent 357d750cab
commit 96ee992ac3
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

@ -32,7 +32,7 @@ bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock,
std::unique_ptr<CCoinsViewCursor> CCoinsViewBacked::Cursor() const { return base->Cursor(); }
size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), cachedCoinsUsage(0) {}
CCoinsViewCache::CCoinsViewCache(CCoinsView* baseIn) : CCoinsViewBacked(baseIn) {}
size_t CCoinsViewCache::DynamicMemoryUsage() const {
return memusage::DynamicUsage(cacheCoins) + cachedCoinsUsage;

@ -220,7 +220,7 @@ protected:
mutable CCoinsMap cacheCoins;
/* Cached dynamic memory usage for the inner Coin objects. */
mutable size_t cachedCoinsUsage;
mutable size_t cachedCoinsUsage{0};
public:
CCoinsViewCache(CCoinsView *baseIn);

@ -239,7 +239,7 @@ void Transform(uint32_t* s, const unsigned char* chunk)
////// RIPEMD160
CRIPEMD160::CRIPEMD160() : bytes(0)
CRIPEMD160::CRIPEMD160()
{
ripemd160::Initialize(s);
}

@ -14,7 +14,7 @@ class CRIPEMD160
private:
uint32_t s[5];
unsigned char buf[64];
uint64_t bytes;
uint64_t bytes{0};
public:
static const size_t OUTPUT_SIZE = 20;

@ -146,7 +146,7 @@ void Transform(uint32_t* s, const unsigned char* chunk)
////// SHA1
CSHA1::CSHA1() : bytes(0)
CSHA1::CSHA1()
{
sha1::Initialize(s);
}

@ -14,7 +14,7 @@ class CSHA1
private:
uint32_t s[5];
unsigned char buf[64];
uint64_t bytes;
uint64_t bytes{0};
public:
static const size_t OUTPUT_SIZE = 20;

@ -673,7 +673,7 @@ std::string SHA256AutoDetect()
////// SHA-256
CSHA256::CSHA256() : bytes(0)
CSHA256::CSHA256()
{
sha256::Initialize(s);
}

@ -15,7 +15,7 @@ class CSHA256
private:
uint32_t s[8];
unsigned char buf[64];
uint64_t bytes;
uint64_t bytes{0};
public:
static const size_t OUTPUT_SIZE = 32;

@ -151,7 +151,7 @@ void Transform(uint64_t* s, const unsigned char* chunk)
////// SHA-512
CSHA512::CSHA512() : bytes(0)
CSHA512::CSHA512()
{
sha512::Initialize(s);
}

@ -14,7 +14,7 @@ class CSHA512
private:
uint64_t s[8];
unsigned char buf[128];
uint64_t bytes;
uint64_t bytes{0};
public:
static constexpr size_t OUTPUT_SIZE = 64;

@ -166,7 +166,7 @@ private:
std::vector<Element> table;
/** size stores the total available slots in the hash table */
uint32_t size;
uint32_t size{0};
/** The bit_packed_atomic_flags array is marked mutable because we want
* garbage collection to be allowed to occur from const methods */
@ -183,7 +183,7 @@ private:
* decremented on insert and reset to the new number of inserts which would
* cause the epoch to reach epoch_size when it reaches zero.
*/
uint32_t epoch_heuristic_counter;
uint32_t epoch_heuristic_counter{0};
/** epoch_size is set to be the number of elements supposed to be in a
* epoch. When the number of non-erased elements in an epoch
@ -193,12 +193,12 @@ private:
* one "dead" which has been erased, one "dying" which has been marked to be
* erased next, and one "living" which new inserts add to.
*/
uint32_t epoch_size;
uint32_t epoch_size{0};
/** depth_limit determines how many elements insert should try to replace.
* Should be set to log2(n).
*/
uint8_t depth_limit;
uint8_t depth_limit{0};
/** hash_function is a const instance of the hash function. It cannot be
* static or initialized at call time as it may have internal state (such as
@ -322,8 +322,7 @@ public:
/** You must always construct a cache with some elements via a subsequent
* call to setup or setup_bytes, otherwise operations may segfault.
*/
cache() : table(), size(), collection_flags(0), epoch_flags(),
epoch_heuristic_counter(), epoch_size(), depth_limit(0), hash_function()
cache() : table(), collection_flags(0), epoch_flags(), hash_function()
{
}

@ -71,13 +71,13 @@ private:
DataStream ssKey{};
CDataStream ssValue;
size_t size_estimate;
size_t size_estimate{0};
public:
/**
* @param[in] _parent CDBWrapper that this batch is to be submitted to
*/
explicit CDBBatch(const CDBWrapper& _parent) : parent(_parent), ssValue(SER_DISK, CLIENT_VERSION), size_estimate(0){};
explicit CDBBatch(const CDBWrapper& _parent) : parent(_parent), ssValue(SER_DISK, CLIENT_VERSION){};
void Clear()
{

@ -42,10 +42,10 @@ public:
private:
//! Whether this private key is valid. We check for correctness when modifying the key
//! data, so fValid should always correspond to the actual state.
bool fValid;
bool fValid{false};
//! Whether the public key corresponding to this private key is (to be) compressed.
bool fCompressed;
bool fCompressed{false};
//! The actual byte data
std::vector<unsigned char, secure_allocator<unsigned char> > keydata;
@ -55,7 +55,7 @@ private:
public:
//! Construct an invalid private key.
CKey() : fValid(false), fCompressed(false)
CKey()
{
// Important: vch must be 32 bytes in length to not break serialization
keydata.resize(32);

@ -528,7 +528,7 @@ bool CBlockPolicyEstimator::_removeTx(const uint256& hash, bool inBlock)
}
CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath)
: m_estimation_filepath{estimation_filepath}, nBestSeenHeight{0}, firstRecordedHeight{0}, historicalFirst{0}, historicalBest{0}, trackedTxs{0}, untrackedTxs{0}
: m_estimation_filepath{estimation_filepath}
{
static_assert(MIN_BUCKET_FEERATE > 0, "Min feerate must be nonzero");
size_t bucketIndex = 0;

@ -242,16 +242,16 @@ public:
private:
mutable Mutex m_cs_fee_estimator;
unsigned int nBestSeenHeight GUARDED_BY(m_cs_fee_estimator);
unsigned int firstRecordedHeight GUARDED_BY(m_cs_fee_estimator);
unsigned int historicalFirst GUARDED_BY(m_cs_fee_estimator);
unsigned int historicalBest GUARDED_BY(m_cs_fee_estimator);
unsigned int nBestSeenHeight GUARDED_BY(m_cs_fee_estimator){0};
unsigned int firstRecordedHeight GUARDED_BY(m_cs_fee_estimator){0};
unsigned int historicalFirst GUARDED_BY(m_cs_fee_estimator){0};
unsigned int historicalBest GUARDED_BY(m_cs_fee_estimator){0};
struct TxStatsInfo
{
unsigned int blockHeight;
unsigned int bucketIndex;
TxStatsInfo() : blockHeight(0), bucketIndex(0) {}
unsigned int blockHeight{0};
unsigned int bucketIndex{0};
TxStatsInfo() {}
};
// map of txids to information about that transaction
@ -262,8 +262,8 @@ private:
std::unique_ptr<TxConfirmStats> shortStats PT_GUARDED_BY(m_cs_fee_estimator);
std::unique_ptr<TxConfirmStats> longStats PT_GUARDED_BY(m_cs_fee_estimator);
unsigned int trackedTxs GUARDED_BY(m_cs_fee_estimator);
unsigned int untrackedTxs GUARDED_BY(m_cs_fee_estimator);
unsigned int trackedTxs GUARDED_BY(m_cs_fee_estimator){0};
unsigned int untrackedTxs GUARDED_BY(m_cs_fee_estimator){0};
std::vector<double> buckets GUARDED_BY(m_cs_fee_estimator); // The upper-bound of the range for the bucket (inclusive)
std::map<double, unsigned int> bucketMap GUARDED_BY(m_cs_fee_estimator); // Map of bucket upper-bound to index into all vectors by bucket

@ -1005,11 +1005,11 @@ struct CSerActionUnserialize
class CSizeComputer
{
protected:
size_t nSize;
size_t nSize{0};
const int nVersion;
public:
explicit CSizeComputer(int nVersionIn) : nSize(0), nVersion(nVersionIn) {}
explicit CSizeComputer(int nVersionIn) : nVersion(nVersionIn) {}
void write(Span<const std::byte> src)
{

@ -96,7 +96,7 @@ template<typename C>
class Span
{
C* m_data;
std::size_t m_size;
std::size_t m_size{0};
template <class T>
struct is_Span_int : public std::false_type {};
@ -107,7 +107,7 @@ class Span
public:
constexpr Span() noexcept : m_data(nullptr), m_size(0) {}
constexpr Span() noexcept : m_data(nullptr) {}
/** Construct a span from a begin pointer and a size.
*

@ -628,8 +628,8 @@ private:
const int nVersion;
FILE *src; //!< source file
uint64_t nSrcPos; //!< how many bytes have been read from source
uint64_t m_read_pos; //!< how many bytes have been read from this
uint64_t nSrcPos{0}; //!< how many bytes have been read from source
uint64_t m_read_pos{0}; //!< how many bytes have been read from this
uint64_t nReadLimit; //!< up to which position we're allowed to read
uint64_t nRewind; //!< how many bytes we guarantee to rewind
std::vector<std::byte> vchBuf; //!< the buffer
@ -675,7 +675,7 @@ private:
public:
CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
: nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), m_read_pos(0), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0})
: nType(nTypeIn), nVersion(nVersionIn), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0})
{
if (nRewindIn >= nBufSize)
throw std::ios_base::failure("Rewind limit must be less than buffer size");

@ -280,8 +280,8 @@ size_t PosixLockedPageAllocator::GetLimit()
/*******************************************************************************/
// Implementation: LockedPool
LockedPool::LockedPool(std::unique_ptr<LockedPageAllocator> allocator_in, LockingFailed_Callback lf_cb_in):
allocator(std::move(allocator_in)), lf_cb(lf_cb_in), cumulative_bytes_locked(0)
LockedPool::LockedPool(std::unique_ptr<LockedPageAllocator> allocator_in, LockingFailed_Callback lf_cb_in)
: allocator(std::move(allocator_in)), lf_cb(lf_cb_in)
{
}

@ -198,7 +198,7 @@ private:
std::list<LockedPageArena> arenas;
LockingFailed_Callback lf_cb;
size_t cumulative_bytes_locked;
size_t cumulative_bytes_locked{0};
/** Mutex protects access to this pool's data structures, including arenas.
*/
mutable std::mutex mutex;

@ -103,7 +103,7 @@ constexpr auto ALL_NETWORKS = std::array{
class StaticContentsSock : public Sock
{
public:
explicit StaticContentsSock(const std::string& contents) : m_contents{contents}, m_consumed{0}
explicit StaticContentsSock(const std::string& contents) : m_contents{contents}
{
// Just a dummy number that is not INVALID_SOCKET.
m_socket = INVALID_SOCKET - 1;
@ -191,7 +191,7 @@ public:
private:
const std::string m_contents;
mutable size_t m_consumed;
mutable size_t m_consumed{0};
};
std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext& random_context);

@ -508,9 +508,6 @@ class FormatArg
{
public:
FormatArg()
: m_value(nullptr),
m_formatImpl(nullptr),
m_toIntImpl(nullptr)
{ }
template<typename T>
@ -549,10 +546,10 @@ class FormatArg
return convertToInt<T>::invoke(*static_cast<const T*>(value));
}
const void* m_value;
const void* m_value{nullptr};
void (*m_formatImpl)(std::ostream& out, const char* fmtBegin,
const char* fmtEnd, int ntrunc, const void* value);
int (*m_toIntImpl)(const void* value);
const char* fmtEnd, int ntrunc, const void* value){nullptr};
int (*m_toIntImpl)(const void* value){nullptr};
};

@ -53,8 +53,8 @@ static const uint16_t DEFAULT_TOR_SOCKS_PORT = 9050;
/****** Low-level TorControlConnection ********/
TorControlConnection::TorControlConnection(struct event_base *_base):
base(_base), b_conn(nullptr)
TorControlConnection::TorControlConnection(struct event_base* _base)
: base(_base)
{
}

@ -93,7 +93,7 @@ private:
/** Libevent event base */
struct event_base *base;
/** Connection to control socket */
struct bufferevent *b_conn;
struct bufferevent* b_conn{nullptr};
/** Message being received */
TorControlReply message;
/** Response handlers */

@ -13,8 +13,8 @@
class JSONUTF8StringFilter
{
public:
explicit JSONUTF8StringFilter(std::string &s):
str(s), is_valid(true), codepoint(0), state(0), surpair(0)
explicit JSONUTF8StringFilter(std::string& s)
: str(s)
{
}
// Write single 8-bit char (may be part of UTF-8 sequence)
@ -79,10 +79,10 @@ public:
}
private:
std::string &str;
bool is_valid;
bool is_valid{true};
// Current UTF-8 decoding state
unsigned int codepoint;
int state; // Top bit to be filled in for next UTF-8 byte, or 0
unsigned int codepoint{0};
int state{0}; // Top bit to be filled in for next UTF-8 byte, or 0
// Keep track of the following state to handle the following section of
// RFC4627:
@ -94,7 +94,7 @@ private:
// "\uD834\uDD1E".
//
// Two subsequent \u.... may have to be replaced with one actual codepoint.
unsigned int surpair; // First half of open UTF-16 surrogate pair, or 0
unsigned int surpair{0}; // First half of open UTF-16 surrogate pair, or 0
void append_codepoint(unsigned int codepoint_)
{

@ -181,9 +181,9 @@ public:
* Auxiliary requested/occurred events to wait for in `WaitMany()`.
*/
struct Events {
explicit Events(Event req) : requested{req}, occurred{0} {}
explicit Events(Event req) : requested{req} {}
Event requested;
Event occurred;
Event occurred{0};
};
struct HashSharedPtrSock {

@ -308,7 +308,7 @@ BerkeleyDatabase::~BerkeleyDatabase()
}
}
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_database(database)
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, bool fFlushOnCloseIn) : m_database(database)
{
database.AddRef();
database.Open();

@ -207,9 +207,9 @@ private:
bool HasKey(DataStream&& key) override;
protected:
Db* pdb;
Db* pdb{nullptr};
std::string strFile;
DbTxn* activeTxn;
DbTxn* activeTxn{nullptr};
bool fReadOnly;
bool fFlushOnClose;
BerkeleyEnvironment *env;

@ -123,7 +123,7 @@ class WalletDatabase
{
public:
/** Create dummy DB handle */
WalletDatabase() : nUpdateCounter(0), nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0) {}
WalletDatabase() : nUpdateCounter(0) {}
virtual ~WalletDatabase() {};
/** Open the database if it is not already opened. */
@ -165,9 +165,9 @@ public:
virtual std::string Format() = 0;
std::atomic<unsigned int> nUpdateCounter;
unsigned int nLastSeen;
unsigned int nLastFlushed;
int64_t nLastWalletUpdate;
unsigned int nLastSeen{0};
unsigned int nLastFlushed{0};
int64_t nLastWalletUpdate{0};
/** Make a DatabaseBatch connected to this database */
virtual std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) = 0;

@ -954,10 +954,10 @@ private:
using Clock = std::chrono::steady_clock;
using NowFn = std::function<Clock::time_point()>;
CWallet& m_wallet;
bool m_could_reserve;
bool m_could_reserve{false};
NowFn m_now;
public:
explicit WalletRescanReserver(CWallet& w) : m_wallet(w), m_could_reserve(false) {}
explicit WalletRescanReserver(CWallet& w) : m_wallet(w) {}
bool reserve()
{

@ -20,7 +20,7 @@ class CZMQAbstractNotifier
public:
static const int DEFAULT_ZMQ_SNDHWM {1000};
CZMQAbstractNotifier() : psocket(nullptr), outbound_message_high_water_mark(DEFAULT_ZMQ_SNDHWM) { }
CZMQAbstractNotifier() : outbound_message_high_water_mark(DEFAULT_ZMQ_SNDHWM) {}
virtual ~CZMQAbstractNotifier();
template <typename T>
@ -57,7 +57,7 @@ public:
virtual bool NotifyTransaction(const CTransaction &transaction);
protected:
void *psocket;
void* psocket{nullptr};
std::string type;
std::string address;
int outbound_message_high_water_mark; // aka SNDHWM

@ -21,7 +21,7 @@
#include <utility>
#include <vector>
CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(nullptr)
CZMQNotificationInterface::CZMQNotificationInterface()
{
}

@ -39,7 +39,7 @@ protected:
private:
CZMQNotificationInterface();
void *pcontext;
void* pcontext{nullptr};
std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
};

Loading…
Cancel
Save