Skip to content

Commit f13e03c

Browse files
author
MarcoFalke
committed
Merge #20584: Declare de facto const reference variables/member functions as const
31b136e Don't declare de facto const reference variables as non-const (practicalswift) 1c65c07 Don't declare de facto const member functions as non-const (practicalswift) Pull request description: _Meta: This is the second and final part of the `const` refactoring series (part one: #20581). **I promise: no more refactoring PRs from me in a while! :)** I'll now go back to focusing on fuzzing/hardening!_ Changes in this PR: * Don't declare de facto const member functions as non-const * Don't declare de facto const reference variables as non-const Awards for finding candidates for the above changes go to: * `clang-tidy`'s [`readability-make-member-function-const`](https://clang.llvm.org/extra/clang-tidy/checks/readability-make-member-function-const.html) check ([list of `clang-tidy` checks](https://clang.llvm.org/extra/clang-tidy/checks/list.html)) * `cppcheck`'s `constVariable` check ([list of `cppcheck` checks](https://sourceforge.net/p/cppcheck/wiki/ListOfChecks/)) See #18920 for instructions on how to analyse Bitcoin Core using Clang Static Analysis, `clang-tidy` and `cppcheck`. ACKs for top commit: ajtowns: ACK 31b136e jonatack: ACK 31b136e theStack: ACK 31b136e ❄️ Tree-SHA512: f58f8f00744219426874379e9f3e9331132b9b48e954d24f3a85cbb858fdcc98009ed42ef7e7b4619ae8af9fc240a6d8bfc1c438db2e97b0ecd722a80dcfeffe
2 parents 3b6d1b6 + 31b136e commit f13e03c

17 files changed

+27
-27
lines changed

src/addrman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
617617
return CAddrInfo();
618618
}
619619

620-
CAddrInfo& newInfo = mapInfo[id_new];
620+
const CAddrInfo& newInfo = mapInfo[id_new];
621621

622622
// which tried bucket to move the entry to
623623
int tried_bucket = newInfo.GetTriedBucket(nKey, m_asmap);

src/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
174174
return false;
175175
}
176176

177-
std::vector<LogCategory> BCLog::Logger::LogCategoriesList()
177+
std::vector<LogCategory> BCLog::Logger::LogCategoriesList() const
178178
{
179179
std::vector<LogCategory> ret;
180180
for (const CLogCategoryDesc& category_desc : LogCategories) {

src/logging.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ namespace BCLog {
135135

136136
bool WillLogCategory(LogFlags category) const;
137137
/** Returns a vector of the log categories */
138-
std::vector<LogCategory> LogCategoriesList();
138+
std::vector<LogCategory> LogCategoriesList() const;
139139
/** Returns a string with the log categories */
140-
std::string LogCategoriesString()
140+
std::string LogCategoriesString() const
141141
{
142142
return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
143143
};

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
213213
// - transaction finality (locktime)
214214
// - premature witness (in case segwit transactions are added to mempool before
215215
// segwit activation)
216-
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package)
216+
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
217217
{
218218
for (CTxMemPool::txiter it : package) {
219219
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))

src/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class BlockAssembler
185185
* locktime, premature-witness, serialized size (if necessary)
186186
* These checks should always succeed, and they're here
187187
* only as an extra check in case of suboptimal node configuration */
188-
bool TestPackageTransactions(const CTxMemPool::setEntries& package);
188+
bool TestPackageTransactions(const CTxMemPool::setEntries& package) const;
189189
/** Return true if given transaction from mapTx has already been evaluated,
190190
* or if the transaction's cached data in mapTx is incorrect. */
191191
bool SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs);

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ void CConnman::NotifyNumConnectionsChanged()
12061206
}
12071207
}
12081208

1209-
void CConnman::InactivityCheck(CNode *pnode)
1209+
void CConnman::InactivityCheck(CNode *pnode) const
12101210
{
12111211
int64_t nTime = GetSystemTimeInSeconds();
12121212
if (nTime - pnode->nTimeConnected > m_peer_connect_timeout)

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class CConnman
420420
void AcceptConnection(const ListenSocket& hListenSocket);
421421
void DisconnectNodes();
422422
void NotifyNumConnectionsChanged();
423-
void InactivityCheck(CNode *pnode);
423+
void InactivityCheck(CNode *pnode) const;
424424
bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
425425
void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
426426
void SocketHandler();

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ NodeContext& EnsureNodeContext(const util::Ref& context)
6666

6767
CTxMemPool& EnsureMemPool(const util::Ref& context)
6868
{
69-
NodeContext& node = EnsureNodeContext(context);
69+
const NodeContext& node = EnsureNodeContext(context);
7070
if (!node.mempool) {
7171
throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found");
7272
}
@@ -75,7 +75,7 @@ CTxMemPool& EnsureMemPool(const util::Ref& context)
7575

7676
ChainstateManager& EnsureChainman(const util::Ref& context)
7777
{
78-
NodeContext& node = EnsureNodeContext(context);
78+
const NodeContext& node = EnsureNodeContext(context);
7979
if (!node.chainman) {
8080
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
8181
}

src/script/interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ class ConditionStack {
305305
uint32_t m_first_false_pos = NO_FALSE;
306306

307307
public:
308-
bool empty() { return m_stack_size == 0; }
309-
bool all_true() { return m_first_false_pos == NO_FALSE; }
308+
bool empty() const { return m_stack_size == 0; }
309+
bool all_true() const { return m_first_false_pos == NO_FALSE; }
310310
void push_back(bool f)
311311
{
312312
if (m_first_false_pos == NO_FALSE && !f) {

src/script/sign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, C
388388
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType)
389389
{
390390
assert(nIn < txTo.vin.size());
391-
CTxIn& txin = txTo.vin[nIn];
391+
const CTxIn& txin = txTo.vin[nIn];
392392
assert(txin.prevout.n < txFrom.vout.size());
393393
const CTxOut& txout = txFrom.vout[txin.prevout.n];
394394

0 commit comments

Comments
 (0)