Skip to content

Commit

Permalink
Merge #10969: Declare single-argument (non-converting) constructors "…
Browse files Browse the repository at this point in the history
…explicit"

64fb0ac Declare single-argument (non-converting) constructors "explicit" (practicalswift)

Pull request description:

  Declare single-argument (non-converting) constructors `explicit`.

  In order to avoid unintended implicit conversions.

  For a more thorough discussion, see ["C.46: By default, declare single-argument constructors explicit"](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit) in the C++ Core Guidelines (Stroustrup & Sutter).

Tree-SHA512: e0c6922e56b11fa402621a38656d8b1122d16dd8f160e78626385373cf184ac7f26cb4c1851eca47e9b0dbd5e924e39a85c3cbdcb627a05ee3a655ecf5f7a0f1
  • Loading branch information
laanwj committed Aug 18, 2017
2 parents 22e301a + 64fb0ac commit 4afb5aa
Show file tree
Hide file tree
Showing 68 changed files with 105 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/addrdb.h
Expand Up @@ -37,7 +37,7 @@ class CBanEntry
SetNull();
}

CBanEntry(int64_t nCreateTimeIn)
explicit CBanEntry(int64_t nCreateTimeIn)
{
SetNull();
nCreateTime = nCreateTimeIn;
Expand Down
2 changes: 1 addition & 1 deletion src/base58.cpp
Expand Up @@ -218,7 +218,7 @@ class CBitcoinAddressVisitor : public boost::static_visitor<bool>
CBitcoinAddress* addr;

public:
CBitcoinAddressVisitor(CBitcoinAddress* addrIn) : addr(addrIn) {}
explicit CBitcoinAddressVisitor(CBitcoinAddress* addrIn) : addr(addrIn) {}

bool operator()(const CKeyID& id) const { return addr->Set(id); }
bool operator()(const CScriptID& id) const { return addr->Set(id); }
Expand Down
2 changes: 1 addition & 1 deletion src/bench/checkqueue.cpp
Expand Up @@ -67,7 +67,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::State& state)
prevector<PREVECTOR_SIZE, uint8_t> p;
PrevectorJob(){
}
PrevectorJob(FastRandomContext& insecure_rand){
explicit PrevectorJob(FastRandomContext& insecure_rand){
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
}
bool operator()()
Expand Down
6 changes: 3 additions & 3 deletions src/blockencodings.h
Expand Up @@ -16,7 +16,7 @@ struct TransactionCompressor {
private:
CTransactionRef& tx;
public:
TransactionCompressor(CTransactionRef& txIn) : tx(txIn) {}
explicit TransactionCompressor(CTransactionRef& txIn) : tx(txIn) {}

ADD_SERIALIZE_METHODS;

Expand Down Expand Up @@ -75,7 +75,7 @@ class BlockTransactions {
std::vector<CTransactionRef> txn;

BlockTransactions() {}
BlockTransactions(const BlockTransactionsRequest& req) :
explicit BlockTransactions(const BlockTransactionsRequest& req) :
blockhash(req.blockhash), txn(req.indexes.size()) {}

ADD_SERIALIZE_METHODS;
Expand Down Expand Up @@ -198,7 +198,7 @@ class PartiallyDownloadedBlock {
CTxMemPool* pool;
public:
CBlockHeader header;
PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}

// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn);
Expand Down
2 changes: 1 addition & 1 deletion src/chain.h
Expand Up @@ -247,7 +247,7 @@ class CBlockIndex
SetNull();
}

CBlockIndex(const CBlockHeader& block)
explicit CBlockIndex(const CBlockHeader& block)
{
SetNull();

Expand Down
2 changes: 1 addition & 1 deletion src/checkqueue.h
Expand Up @@ -131,7 +131,7 @@ class CCheckQueue
boost::mutex ControlMutex;

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

//! Worker thread
void Thread()
Expand Down
4 changes: 2 additions & 2 deletions src/compressor.h
Expand Up @@ -53,7 +53,7 @@ class CScriptCompressor
unsigned int GetSpecialSize(unsigned int nSize) const;
bool Decompress(unsigned int nSize, const std::vector<unsigned char> &out);
public:
CScriptCompressor(CScript &scriptIn) : script(scriptIn) { }
explicit CScriptCompressor(CScript &scriptIn) : script(scriptIn) { }

template<typename Stream>
void Serialize(Stream &s) const {
Expand Down Expand Up @@ -99,7 +99,7 @@ class CTxOutCompressor
static uint64_t CompressAmount(uint64_t nAmount);
static uint64_t DecompressAmount(uint64_t nAmount);

CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
explicit CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }

ADD_SERIALIZE_METHODS;

Expand Down
8 changes: 4 additions & 4 deletions src/crypto/aes.h
Expand Up @@ -22,7 +22,7 @@ class AES128Encrypt
AES128_ctx ctx;

public:
AES128Encrypt(const unsigned char key[16]);
explicit AES128Encrypt(const unsigned char key[16]);
~AES128Encrypt();
void Encrypt(unsigned char ciphertext[16], const unsigned char plaintext[16]) const;
};
Expand All @@ -34,7 +34,7 @@ class AES128Decrypt
AES128_ctx ctx;

public:
AES128Decrypt(const unsigned char key[16]);
explicit AES128Decrypt(const unsigned char key[16]);
~AES128Decrypt();
void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const;
};
Expand All @@ -46,7 +46,7 @@ class AES256Encrypt
AES256_ctx ctx;

public:
AES256Encrypt(const unsigned char key[32]);
explicit AES256Encrypt(const unsigned char key[32]);
~AES256Encrypt();
void Encrypt(unsigned char ciphertext[16], const unsigned char plaintext[16]) const;
};
Expand All @@ -58,7 +58,7 @@ class AES256Decrypt
AES256_ctx ctx;

public:
AES256Decrypt(const unsigned char key[32]);
explicit AES256Decrypt(const unsigned char key[32]);
~AES256Decrypt();
void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const;
};
Expand Down
2 changes: 1 addition & 1 deletion src/cuckoocache.h
Expand Up @@ -58,7 +58,7 @@ class bit_packed_atomic_flags
* @post All calls to bit_is_set (without subsequent bit_unset) will return
* true.
*/
bit_packed_atomic_flags(uint32_t size)
explicit bit_packed_atomic_flags(uint32_t size)
{
// pad out the size if needed
size = (size + 7) / 8;
Expand Down
4 changes: 2 additions & 2 deletions src/dbwrapper.h
Expand Up @@ -22,7 +22,7 @@ static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
class dbwrapper_error : public std::runtime_error
{
public:
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
explicit dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
};

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

void Clear()
{
Expand Down
2 changes: 1 addition & 1 deletion src/hash.h
Expand Up @@ -168,7 +168,7 @@ class CHashVerifier : public CHashWriter
Source* source;

public:
CHashVerifier(Source* source_) : CHashWriter(source_->GetType(), source_->GetVersion()), source(source_) {}
explicit CHashVerifier(Source* source_) : CHashWriter(source_->GetType(), source_->GetVersion()), source(source_) {}

void read(char* pch, size_t nSize)
{
Expand Down
2 changes: 1 addition & 1 deletion src/httprpc.cpp
Expand Up @@ -43,7 +43,7 @@ class HTTPRPCTimer : public RPCTimerBase
class HTTPRPCTimerInterface : public RPCTimerInterface
{
public:
HTTPRPCTimerInterface(struct event_base* _base) : base(_base)
explicit HTTPRPCTimerInterface(struct event_base* _base) : base(_base)
{
}
const char* Name() override
Expand Down
4 changes: 2 additions & 2 deletions src/httpserver.cpp
Expand Up @@ -79,7 +79,7 @@ class WorkQueue
{
public:
WorkQueue &wq;
ThreadCounter(WorkQueue &w): wq(w)
explicit ThreadCounter(WorkQueue &w): wq(w)
{
std::lock_guard<std::mutex> lock(wq.cs);
wq.numThreads += 1;
Expand All @@ -93,7 +93,7 @@ class WorkQueue
};

public:
WorkQueue(size_t _maxDepth) : running(true),
explicit WorkQueue(size_t _maxDepth) : running(true),
maxDepth(_maxDepth),
numThreads(0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/httpserver.h
Expand Up @@ -61,7 +61,7 @@ class HTTPRequest
bool replySent;

public:
HTTPRequest(struct evhttp_request* req);
explicit HTTPRequest(struct evhttp_request* req);
~HTTPRequest();

enum RequestMethod {
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Expand Up @@ -136,7 +136,7 @@ bool ShutdownRequested()
class CCoinsViewErrorCatcher : public CCoinsViewBacked
{
public:
CCoinsViewErrorCatcher(CCoinsView* view) : CCoinsViewBacked(view) {}
explicit CCoinsViewErrorCatcher(CCoinsView* view) : CCoinsViewBacked(view) {}
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override {
try {
return CCoinsViewBacked::GetCoin(outpoint, coin);
Expand Down
2 changes: 1 addition & 1 deletion src/limitedmap.h
Expand Up @@ -27,7 +27,7 @@ class limitedmap
size_type nMaxSize;

public:
limitedmap(size_type nMaxSizeIn)
explicit limitedmap(size_type nMaxSizeIn)
{
assert(nMaxSizeIn > 0);
nMaxSize = nMaxSizeIn;
Expand Down
6 changes: 3 additions & 3 deletions src/miner.h
Expand Up @@ -33,7 +33,7 @@ struct CBlockTemplate
// Container for tracking updates to ancestor feerate as we include (parent)
// transactions in a block
struct CTxMemPoolModifiedEntry {
CTxMemPoolModifiedEntry(CTxMemPool::txiter entry)
explicit CTxMemPoolModifiedEntry(CTxMemPool::txiter entry)
{
iter = entry;
nSizeWithAncestors = entry->GetSizeWithAncestors();
Expand Down Expand Up @@ -116,7 +116,7 @@ typedef indexed_modified_transaction_set::index<ancestor_score>::type::iterator

struct update_for_parent_inclusion
{
update_for_parent_inclusion(CTxMemPool::txiter it) : iter(it) {}
explicit update_for_parent_inclusion(CTxMemPool::txiter it) : iter(it) {}

void operator() (CTxMemPoolModifiedEntry &e)
{
Expand Down Expand Up @@ -164,7 +164,7 @@ class BlockAssembler
CFeeRate blockMinFeeRate;
};

BlockAssembler(const CChainParams& params);
explicit BlockAssembler(const CChainParams& params);
BlockAssembler(const CChainParams& params, const Options& options);

/** Construct a new block template with coinbase to scriptPubKeyIn */
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Expand Up @@ -2783,7 +2783,7 @@ class CompareInvMempoolOrder
{
CTxMemPool *mp;
public:
CompareInvMempoolOrder(CTxMemPool *_mempool)
explicit CompareInvMempoolOrder(CTxMemPool *_mempool)
{
mp = _mempool;
}
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.h
Expand Up @@ -32,7 +32,7 @@ class PeerLogicValidation : public CValidationInterface {
CConnman* connman;

public:
PeerLogicValidation(CConnman* connmanIn);
explicit PeerLogicValidation(CConnman* connmanIn);

void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted) override;
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
Expand Down
8 changes: 4 additions & 4 deletions src/netaddress.h
Expand Up @@ -36,7 +36,7 @@ class CNetAddr

public:
CNetAddr();
CNetAddr(const struct in_addr& ipv4Addr);
explicit CNetAddr(const struct in_addr& ipv4Addr);
void Init();
void SetIP(const CNetAddr& ip);

Expand Down Expand Up @@ -82,7 +82,7 @@ class CNetAddr
std::vector<unsigned char> GetGroup() const;
int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;

CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
bool GetIn6Addr(struct in6_addr* pipv6Addr) const;

friend bool operator==(const CNetAddr& a, const CNetAddr& b);
Expand Down Expand Up @@ -146,7 +146,7 @@ class CService : public CNetAddr
CService();
CService(const CNetAddr& ip, unsigned short port);
CService(const struct in_addr& ipv4Addr, unsigned short port);
CService(const struct sockaddr_in& addr);
explicit CService(const struct sockaddr_in& addr);
void Init();
unsigned short GetPort() const;
bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const;
Expand All @@ -160,7 +160,7 @@ class CService : public CNetAddr
std::string ToStringIPPort() const;

CService(const struct in6_addr& ipv6Addr, unsigned short port);
CService(const struct sockaddr_in6& addr);
explicit CService(const struct sockaddr_in6& addr);

ADD_SERIALIZE_METHODS;

Expand Down
2 changes: 1 addition & 1 deletion src/netbase.h
Expand Up @@ -29,7 +29,7 @@ class proxyType
{
public:
proxyType(): randomize_credentials(false) {}
proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
explicit proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}

bool IsValid() const { return proxy.IsValid(); }

Expand Down
2 changes: 1 addition & 1 deletion src/netmessagemaker.h
Expand Up @@ -12,7 +12,7 @@
class CNetMsgMaker
{
public:
CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){}
explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){}

template <typename... Args>
CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args) const
Expand Down
2 changes: 1 addition & 1 deletion src/policy/fees.h
Expand Up @@ -284,7 +284,7 @@ class FeeFilterRounder

public:
/** Create new FeeFilterRounder */
FeeFilterRounder(const CFeeRate& minIncrementalFee);
explicit FeeFilterRounder(const CFeeRate& minIncrementalFee);

/** Quantize a minimum fee for privacy purpose before broadcast **/
CAmount round(CAmount currentMinFee);
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/block.h
Expand Up @@ -129,7 +129,7 @@ struct CBlockLocator

CBlockLocator() {}

CBlockLocator(const std::vector<uint256>& vHaveIn) : vHave(vHaveIn) {}
explicit CBlockLocator(const std::vector<uint256>& vHaveIn) : vHave(vHaveIn) {}

ADD_SERIALIZE_METHODS;

Expand Down
2 changes: 1 addition & 1 deletion src/protocol.h
Expand Up @@ -39,7 +39,7 @@ class CMessageHeader
};
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];

CMessageHeader(const MessageStartChars& pchMessageStartIn);
explicit CMessageHeader(const MessageStartChars& pchMessageStartIn);
CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn);

std::string GetCommand() const;
Expand Down
4 changes: 2 additions & 2 deletions src/pubkey.h
Expand Up @@ -30,7 +30,7 @@ class CKeyID : public uint160
{
public:
CKeyID() : uint160() {}
CKeyID(const uint160& in) : uint160(in) {}
explicit CKeyID(const uint160& in) : uint160(in) {}
};

typedef uint256 ChainCode;
Expand Down Expand Up @@ -88,7 +88,7 @@ class CPubKey
}

//! Construct a public key from a byte vector.
CPubKey(const std::vector<unsigned char>& _vch)
explicit CPubKey(const std::vector<unsigned char>& _vch)
{
Set(_vch.begin(), _vch.end());
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/callback.h
Expand Up @@ -16,7 +16,7 @@ class FunctionCallback : public Callback
F f;

public:
FunctionCallback(F f_) : f(std::move(f_)) {}
explicit FunctionCallback(F f_) : f(std::move(f_)) {}
~FunctionCallback() override {}
void call() override { f(this); }
};
Expand Down
6 changes: 3 additions & 3 deletions src/qt/coincontroldialog.h
Expand Up @@ -30,9 +30,9 @@ namespace Ui {
class CCoinControlWidgetItem : public QTreeWidgetItem
{
public:
CCoinControlWidgetItem(QTreeWidget *parent, int type = Type) : QTreeWidgetItem(parent, type) {}
CCoinControlWidgetItem(int type = Type) : QTreeWidgetItem(type) {}
CCoinControlWidgetItem(QTreeWidgetItem *parent, int type = Type) : QTreeWidgetItem(parent, type) {}
explicit CCoinControlWidgetItem(QTreeWidget *parent, int type = Type) : QTreeWidgetItem(parent, type) {}
explicit CCoinControlWidgetItem(int type = Type) : QTreeWidgetItem(type) {}
explicit CCoinControlWidgetItem(QTreeWidgetItem *parent, int type = Type) : QTreeWidgetItem(parent, type) {}

bool operator<(const QTreeWidgetItem &other) const;
};
Expand Down
2 changes: 1 addition & 1 deletion src/qt/intro.cpp
Expand Up @@ -43,7 +43,7 @@ class FreespaceChecker : public QObject
Q_OBJECT

public:
FreespaceChecker(Intro *intro);
explicit FreespaceChecker(Intro *intro);

enum Status {
ST_OK,
Expand Down
2 changes: 1 addition & 1 deletion src/qt/notificator.cpp
Expand Up @@ -93,7 +93,7 @@ class FreedesktopImage
{
public:
FreedesktopImage() {}
FreedesktopImage(const QImage &img);
explicit FreedesktopImage(const QImage &img);

static int metaType();

Expand Down

0 comments on commit 4afb5aa

Please sign in to comment.