diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1050,7 +1050,7 @@ // Erase orphan transactions included or precluded by this block if (vOrphanErase.size()) { int nErased = 0; - for (uint256 &orphanId : vOrphanErase) { + for (const uint256 &orphanId : vOrphanErase) { nErased += EraseOrphanTx(orphanId); } LogPrint(BCLog::MEMPOOL, diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -439,7 +439,7 @@ #ifdef ENABLE_WALLET window->removeAllWallets(); - for (WalletModel *walletModel : m_wallet_models) { + for (const WalletModel *walletModel : m_wallet_models) { delete walletModel; } m_wallet_models.clear(); diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp --- a/src/qt/peertablemodel.cpp +++ b/src/qt/peertablemodel.cpp @@ -61,7 +61,7 @@ interfaces::Node::NodesStats nodes_stats; node.getNodesStats(nodes_stats); cachedNodeStats.reserve(nodes_stats.size()); - for (auto &node_stats : nodes_stats) { + for (const auto &node_stats : nodes_stats) { CNodeCombinedStats stats; stats.nodeStats = std::get<0>(node_stats); stats.fNodeStateStatsAvailable = std::get<1>(node_stats); diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -217,7 +217,7 @@ // Disconnect signals from client m_handler_init_message->disconnect(); m_handler_show_progress->disconnect(); - for (auto &handler : m_connected_wallet_handlers) { + for (const auto &handler : m_connected_wallet_handlers) { handler->disconnect(); } m_connected_wallet_handlers.clear(); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -476,7 +476,7 @@ const CTxMemPool::txiter &it = g_mempool.mapTx.find(tx.GetId()); const CTxMemPool::setEntries &setChildren = g_mempool.GetMemPoolChildren(it); - for (const CTxMemPool::txiter &childiter : setChildren) { + for (CTxMemPool::txiter childiter : setChildren) { spent.push_back(childiter->GetTx().GetId().ToString()); } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -207,7 +207,7 @@ obj.pushKV("synced_headers", statestats.nSyncHeight); obj.pushKV("synced_blocks", statestats.nCommonHeight); UniValue heights(UniValue::VARR); - for (int height : statestats.vHeightInFlight) { + for (const int height : statestats.vHeightInFlight) { heights.push_back(height); } obj.pushKV("inflight", heights); diff --git a/src/test/cuckoocache_tests.cpp b/src/test/cuckoocache_tests.cpp --- a/src/test/cuckoocache_tests.cpp +++ b/src/test/cuckoocache_tests.cpp @@ -70,12 +70,12 @@ */ std::vector hashes_insert_copy = hashes; /** Do the insert */ - for (uint256 &h : hashes_insert_copy) { + for (const uint256 &h : hashes_insert_copy) { set.insert(h); } /** Count the hits */ uint32_t count = 0; - for (uint256 &h : hashes) { + for (const uint256 &h : hashes) { count += set.contains(h, false); } double hit_rate = double(count) / double(n_insert); @@ -327,7 +327,7 @@ for (uint32_t i = n_insert - (n_insert / 4); i < n_insert; ++i) { reads.push_back(inserts[i]); } - for (auto h : inserts) { + for (const auto &h : inserts) { c.insert(h); } } diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -224,7 +224,7 @@ } } - for (int seek_start : {0x00, 0x80}) { + for (const int seek_start : {0x00, 0x80}) { it->Seek((uint8_t)seek_start); for (unsigned int x = seek_start; x < 255; ++x) { uint8_t key; diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -25,7 +25,7 @@ // Convert to char*: std::vector vecChar; - for (std::string &s : vecArg) { + for (const std::string &s : vecArg) { vecChar.push_back(s.c_str()); } diff --git a/src/test/key_io_tests.cpp b/src/test/key_io_tests.cpp --- a/src/test/key_io_tests.cpp +++ b/src/test/key_io_tests.cpp @@ -155,8 +155,9 @@ std::string exp_base58string = test[0].get_str(); // must be invalid as public and as private key - for (auto chain : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, - CBaseChainParams::REGTEST}) { + for (const auto &chain : + {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, + CBaseChainParams::REGTEST}) { SelectParams(chain); destination = DecodeLegacyAddr(exp_base58string, Params()); BOOST_CHECK_MESSAGE(!IsValidDestination(destination), diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -243,7 +243,7 @@ } const setEntries &setMemPoolParents = GetMemPoolParents(stageit); - for (const txiter &phash : setMemPoolParents) { + for (txiter phash : setMemPoolParents) { // If this is a new ancestor, add it. if (setAncestors.count(phash) == 0) { parentHashes.insert(phash); @@ -513,7 +513,7 @@ stage.erase(it); const setEntries &setChildren = GetMemPoolChildren(it); - for (const txiter &childiter : setChildren) { + for (txiter childiter : setChildren) { if (!setDescendants.count(childiter)) { stage.insert(childiter); } @@ -1046,7 +1046,7 @@ MemPoolRemovalReason reason) { AssertLockHeld(cs); UpdateForRemoveFromMempool(stage, updateDescendants); - for (const txiter &it : stage) { + for (txiter it : stage) { removeUnchecked(it, reason); } } diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5020,7 +5020,7 @@ setDirtyBlockIndex.clear(); setDirtyFileInfo.clear(); - for (BlockMap::value_type &entry : mapBlockIndex) { + for (const BlockMap::value_type &entry : mapBlockIndex) { delete entry.second; } @@ -5270,7 +5270,7 @@ // Build forward-pointing map of the entire block tree. std::multimap forward; - for (auto &entry : mapBlockIndex) { + for (const auto &entry : mapBlockIndex) { forward.emplace(entry.second->pprev, entry.second); } diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -548,7 +548,7 @@ // be implemented, so no equality checks are needed at all. (Newer // versions of BDB have an set_lk_exclusive method for this // purpose, but the older version we use does not.) - for (auto &dbenv : g_dbenvs) { + for (const auto &dbenv : g_dbenvs) { CheckUniqueFileid(dbenv.second, strFilename, *pdb_temp); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3184,7 +3184,7 @@ UniValue ret(UniValue::VARR); - for (COutPoint &output : vOutpts) { + for (const COutPoint &output : vOutpts) { UniValue o(UniValue::VOBJ); o.pushKV("txid", output.GetTxId().GetHex()); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1647,7 +1647,7 @@ // Look up the inputs. We should have already checked that this transaction // IsAllFromMe(ISMINE_SPENDABLE), so every input should already be in our // wallet, with a valid index into the vout array, and the ability to sign. - for (auto &input : tx.vin) { + for (const auto &input : tx.vin) { const auto mi = wallet->mapWallet.find(input.prevout.GetTxId()); if (mi == wallet->mapWallet.end()) { return -1; @@ -1924,7 +1924,7 @@ } // Try to add wallet transactions to memory pool. - for (std::pair &item : mapSorted) { + for (const auto &item : mapSorted) { CWalletTx &wtx = *(item.second); CValidationState state; wtx.AcceptToMemoryPool(maxTxFee, state); @@ -2207,7 +2207,7 @@ mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx)); } - for (std::pair &item : mapSorted) { + for (const auto &item : mapSorted) { CWalletTx &wtx = *item.second; if (wtx.RelayWalletTransaction(connman)) { result.push_back(wtx.GetId()); @@ -2528,7 +2528,7 @@ AvailableCoins(availableCoins); - for (auto &coin : availableCoins) { + for (const auto &coin : availableCoins) { CTxDestination address; if (coin.fSpendable && ExtractDestination( @@ -3896,7 +3896,7 @@ // Make a set of all the groups hit by this new group. std::set *> hits; std::map *>::iterator it; - for (CTxDestination address : _grouping) { + for (const CTxDestination &address : _grouping) { if ((it = setmap.find(address)) != setmap.end()) { hits.insert((*it).second); } @@ -3913,13 +3913,13 @@ uniqueGroupings.insert(merged); // Update setmap. - for (CTxDestination element : *merged) { + for (const CTxDestination &element : *merged) { setmap[element] = merged; } } std::set> ret; - for (std::set *uniqueGrouping : uniqueGroupings) { + for (const std::set *uniqueGrouping : uniqueGroupings) { ret.insert(*uniqueGrouping); delete uniqueGrouping; }