Skip to content

Commit 64fb0ac

Browse files
Declare single-argument (non-converting) constructors "explicit"
In order to avoid unintended implicit conversions.
1 parent 22e301a commit 64fb0ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+105
-105
lines changed

src/addrdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CBanEntry
3737
SetNull();
3838
}
3939

40-
CBanEntry(int64_t nCreateTimeIn)
40+
explicit CBanEntry(int64_t nCreateTimeIn)
4141
{
4242
SetNull();
4343
nCreateTime = nCreateTimeIn;

src/base58.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class CBitcoinAddressVisitor : public boost::static_visitor<bool>
218218
CBitcoinAddress* addr;
219219

220220
public:
221-
CBitcoinAddressVisitor(CBitcoinAddress* addrIn) : addr(addrIn) {}
221+
explicit CBitcoinAddressVisitor(CBitcoinAddress* addrIn) : addr(addrIn) {}
222222

223223
bool operator()(const CKeyID& id) const { return addr->Set(id); }
224224
bool operator()(const CScriptID& id) const { return addr->Set(id); }

src/bench/checkqueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::State& state)
6767
prevector<PREVECTOR_SIZE, uint8_t> p;
6868
PrevectorJob(){
6969
}
70-
PrevectorJob(FastRandomContext& insecure_rand){
70+
explicit PrevectorJob(FastRandomContext& insecure_rand){
7171
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
7272
}
7373
bool operator()()

src/blockencodings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct TransactionCompressor {
1616
private:
1717
CTransactionRef& tx;
1818
public:
19-
TransactionCompressor(CTransactionRef& txIn) : tx(txIn) {}
19+
explicit TransactionCompressor(CTransactionRef& txIn) : tx(txIn) {}
2020

2121
ADD_SERIALIZE_METHODS;
2222

@@ -75,7 +75,7 @@ class BlockTransactions {
7575
std::vector<CTransactionRef> txn;
7676

7777
BlockTransactions() {}
78-
BlockTransactions(const BlockTransactionsRequest& req) :
78+
explicit BlockTransactions(const BlockTransactionsRequest& req) :
7979
blockhash(req.blockhash), txn(req.indexes.size()) {}
8080

8181
ADD_SERIALIZE_METHODS;
@@ -198,7 +198,7 @@ class PartiallyDownloadedBlock {
198198
CTxMemPool* pool;
199199
public:
200200
CBlockHeader header;
201-
PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
201+
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
202202

203203
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
204204
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn);

src/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class CBlockIndex
247247
SetNull();
248248
}
249249

250-
CBlockIndex(const CBlockHeader& block)
250+
explicit CBlockIndex(const CBlockHeader& block)
251251
{
252252
SetNull();
253253

src/checkqueue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class CCheckQueue
131131
boost::mutex ControlMutex;
132132

133133
//! Create a new check queue
134-
CCheckQueue(unsigned int nBatchSizeIn) : nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {}
134+
explicit CCheckQueue(unsigned int nBatchSizeIn) : nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {}
135135

136136
//! Worker thread
137137
void Thread()

src/compressor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CScriptCompressor
5353
unsigned int GetSpecialSize(unsigned int nSize) const;
5454
bool Decompress(unsigned int nSize, const std::vector<unsigned char> &out);
5555
public:
56-
CScriptCompressor(CScript &scriptIn) : script(scriptIn) { }
56+
explicit CScriptCompressor(CScript &scriptIn) : script(scriptIn) { }
5757

5858
template<typename Stream>
5959
void Serialize(Stream &s) const {
@@ -99,7 +99,7 @@ class CTxOutCompressor
9999
static uint64_t CompressAmount(uint64_t nAmount);
100100
static uint64_t DecompressAmount(uint64_t nAmount);
101101

102-
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
102+
explicit CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
103103

104104
ADD_SERIALIZE_METHODS;
105105

src/crypto/aes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AES128Encrypt
2222
AES128_ctx ctx;
2323

2424
public:
25-
AES128Encrypt(const unsigned char key[16]);
25+
explicit AES128Encrypt(const unsigned char key[16]);
2626
~AES128Encrypt();
2727
void Encrypt(unsigned char ciphertext[16], const unsigned char plaintext[16]) const;
2828
};
@@ -34,7 +34,7 @@ class AES128Decrypt
3434
AES128_ctx ctx;
3535

3636
public:
37-
AES128Decrypt(const unsigned char key[16]);
37+
explicit AES128Decrypt(const unsigned char key[16]);
3838
~AES128Decrypt();
3939
void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const;
4040
};
@@ -46,7 +46,7 @@ class AES256Encrypt
4646
AES256_ctx ctx;
4747

4848
public:
49-
AES256Encrypt(const unsigned char key[32]);
49+
explicit AES256Encrypt(const unsigned char key[32]);
5050
~AES256Encrypt();
5151
void Encrypt(unsigned char ciphertext[16], const unsigned char plaintext[16]) const;
5252
};
@@ -58,7 +58,7 @@ class AES256Decrypt
5858
AES256_ctx ctx;
5959

6060
public:
61-
AES256Decrypt(const unsigned char key[32]);
61+
explicit AES256Decrypt(const unsigned char key[32]);
6262
~AES256Decrypt();
6363
void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const;
6464
};

src/cuckoocache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class bit_packed_atomic_flags
5858
* @post All calls to bit_is_set (without subsequent bit_unset) will return
5959
* true.
6060
*/
61-
bit_packed_atomic_flags(uint32_t size)
61+
explicit bit_packed_atomic_flags(uint32_t size)
6262
{
6363
// pad out the size if needed
6464
size = (size + 7) / 8;

src/dbwrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
2222
class dbwrapper_error : public std::runtime_error
2323
{
2424
public:
25-
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
25+
explicit dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
2626
};
2727

2828
class CDBWrapper;
@@ -61,7 +61,7 @@ class CDBBatch
6161
/**
6262
* @param[in] _parent CDBWrapper that this batch is to be submitted to
6363
*/
64-
CDBBatch(const CDBWrapper &_parent) : parent(_parent), ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION), size_estimate(0) { };
64+
explicit CDBBatch(const CDBWrapper &_parent) : parent(_parent), ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION), size_estimate(0) { };
6565

6666
void Clear()
6767
{

0 commit comments

Comments
 (0)