diff --git a/src/cuckoocache.h b/src/cuckoocache.h --- a/src/cuckoocache.h +++ b/src/cuckoocache.h @@ -415,7 +415,7 @@ std::array locs = compute_hashes(e); // Make sure we have not already inserted this element. // If we have, make sure that it does not get deleted. - for (uint32_t loc : locs) + for (const uint32_t loc : locs) if (table[loc] == e) { please_keep(loc); epoch_flags[loc] = last_epoch; @@ -423,7 +423,7 @@ } for (uint8_t depth = 0; depth < depth_limit; ++depth) { // First try to insert to an empty slot, if one exists - for (uint32_t loc : locs) { + for (const uint32_t loc : locs) { if (!collection_flags.bit_is_set(loc)) continue; table[loc] = std::move(e); please_keep(loc); @@ -488,7 +488,7 @@ */ inline bool contains(const Element &e, const bool erase) const { std::array locs = compute_hashes(e); - for (uint32_t loc : locs) { + for (const uint32_t loc : locs) { if (table[loc] == e) { if (erase) { allow_erase(loc); 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/bitcoingui.cpp b/src/qt/bitcoingui.cpp --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1295,7 +1295,7 @@ * mouse events. */ void UnitDisplayStatusBarControl::createContextMenu() { menu = new QMenu(this); - for (BitcoinUnits::Unit u : BitcoinUnits::availableUnits()) { + for (const BitcoinUnits::Unit u : BitcoinUnits::availableUnits()) { QAction *menuAction = new QAction(QString(BitcoinUnits::name(u)), this); menuAction->setData(QVariant(u)); menu->addAction(menuAction); 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/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -357,7 +357,7 @@ questionString.append("
"); Amount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee; QStringList alternativeUnits; - for (BitcoinUnits::Unit u : BitcoinUnits::availableUnits()) { + for (const BitcoinUnits::Unit u : BitcoinUnits::availableUnits()) { if (u != model->getOptionsModel()->getDisplayUnit()) { alternativeUnits.append( BitcoinUnits::formatHtmlWithUnit(u, totalAmount)); 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/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -133,10 +133,10 @@ } float tmax = 0.0f; - for (float f : vSamplesIn) { + for (const float f : vSamplesIn) { if (f > tmax) tmax = f; } - for (float f : vSamplesOut) { + for (const float f : vSamplesOut) { if (f > tmax) tmax = f; } fMax = tmax; diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -169,14 +169,14 @@ BitcoinUnits::formatHtmlWithUnit(unit, nNet) + "
"; } else { isminetype fAllFromMe = ISMINE_SPENDABLE; - for (isminetype mine : wtx.txin_is_mine) { + for (const isminetype mine : wtx.txin_is_mine) { if (fAllFromMe > mine) { fAllFromMe = mine; } } isminetype fAllToMe = ISMINE_SPENDABLE; - for (isminetype mine : wtx.txout_is_mine) { + for (const isminetype mine : wtx.txout_is_mine) { if (fAllToMe > mine) { fAllToMe = mine; } diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -75,7 +75,7 @@ } else { bool involvesWatchAddress = false; isminetype fAllFromMe = ISMINE_SPENDABLE; - for (isminetype mine : wtx.txin_is_mine) { + for (const isminetype mine : wtx.txin_is_mine) { if (mine & ISMINE_WATCH_ONLY) { involvesWatchAddress = true; } @@ -85,7 +85,7 @@ } isminetype fAllToMe = ISMINE_SPENDABLE; - for (isminetype mine : wtx.txout_is_mine) { + for (const isminetype mine : wtx.txout_is_mine) { if (mine & ISMINE_WATCH_ONLY) { involvesWatchAddress = true; } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -500,7 +500,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/coins_tests.cpp b/src/test/coins_tests.cpp --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -777,7 +777,7 @@ // while still verifying that the CoinsViewCache::AddCoin implementation ignores // base values. template static void CheckAddCoin(Args &&... args) { - for (Amount base_value : {ABSENT, PRUNED, VALUE1}) { + for (const Amount base_value : {ABSENT, PRUNED, VALUE1}) { CheckAddCoinBase(base_value, std::forward(args)...); } } @@ -897,11 +897,11 @@ // they would be too repetitive (the parent cache is never updated in these // cases). The loop below covers these cases and makes sure the parent cache // is always left unchanged. - for (Amount parent_value : {ABSENT, PRUNED, VALUE1}) { - for (Amount child_value : {ABSENT, PRUNED, VALUE2}) { - for (char parent_flags : + for (const Amount parent_value : {ABSENT, PRUNED, VALUE1}) { + for (const Amount child_value : {ABSENT, PRUNED, VALUE2}) { + for (const char parent_flags : parent_value == ABSENT ? ABSENT_FLAGS : FLAGS) { - for (char child_flags : + for (const char child_flags : child_value == ABSENT ? ABSENT_FLAGS : CLEAN_FLAGS) { CheckWriteCoin(parent_value, child_value, parent_value, parent_flags, child_flags, parent_flags); 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 @@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper) { // Perform tests both obfuscated and non-obfuscated. - for (bool obfuscate : {false, true}) { + for (const bool obfuscate : {false, true}) { fs::path ph = SetDataDir( std::string("dbwrapper").append(obfuscate ? "_true" : "_false")); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); @@ -46,7 +46,7 @@ // Test batch operations BOOST_AUTO_TEST_CASE(dbwrapper_batch) { // Perform tests both obfuscated and non-obfuscated. - for (bool obfuscate : {false, true}) { + for (const bool obfuscate : {false, true}) { fs::path ph = SetDataDir(std::string("dbwrapper_batch") .append(obfuscate ? "_true" : "_false")); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator) { // Perform tests both obfuscated and non-obfuscated. - for (bool obfuscate : {false, true}) { + for (const bool obfuscate : {false, true}) { fs::path ph = SetDataDir(std::string("dbwrapper_iterator") .append(obfuscate ? "_true" : "_false")); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); @@ -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; @@ -302,7 +302,7 @@ std::unique_ptr it( const_cast(dbw).NewIterator()); - for (int seek_start : {0, 5}) { + for (const int seek_start : {0, 5}) { snprintf(buf, sizeof(buf), "%d", seek_start); StringContentsSerializer seek_key(buf); it->Seek(seek_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/test/skiplist_tests.cpp b/src/test/skiplist_tests.cpp --- a/src/test/skiplist_tests.cpp +++ b/src/test/skiplist_tests.cpp @@ -165,7 +165,8 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_edge_test) { std::list blocks; - for (unsigned int timeMax : {100, 100, 100, 200, 200, 200, 300, 300, 300}) { + for (const unsigned int timeMax : + {100, 100, 100, 200, 200, 200, 300, 300, 300}) { CBlockIndex *prev = blocks.empty() ? nullptr : &blocks.back(); blocks.emplace_back(); blocks.back().nHeight = prev ? prev->nHeight + 1 : 0; diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -235,7 +235,7 @@ testArgs.ParseParameters(7, (char **)argv_test, error); // Each letter should be set. - for (char opt : "abcdef") { + for (const char opt : "abcdef") { BOOST_CHECK(testArgs.IsArgSet({'-', opt}) || !opt); } @@ -374,7 +374,7 @@ test_args.GetArg("-zzz", "xxx") == "xxx" && test_args.GetArg("-iii", "xxx") == "xxx"); - for (bool def : {false, true}) { + for (const bool def : {false, true}) { BOOST_CHECK(test_args.GetBoolArg("-a", def) && test_args.GetBoolArg("-b", def) && !test_args.GetBoolArg("-ccc", def) && diff --git a/src/timedata.cpp b/src/timedata.cpp --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -88,7 +88,7 @@ // If nobody has a time different than ours but within 5 minutes // of ours, give a warning bool fMatch = false; - for (int64_t nOffset : vSorted) { + for (const int64_t nOffset : vSorted) { if (nOffset != 0 && abs64(nOffset) < 5 * 60) fMatch = true; } @@ -107,7 +107,7 @@ } if (LogAcceptCategory(BCLog::NET)) { - for (int64_t n : vSorted) { + for (const int64_t n : vSorted) { LogPrintToBeContinued(BCLog::NET, "%+d ", n); } diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -242,7 +242,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); @@ -509,7 +509,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); } @@ -1037,7 +1037,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 @@ -416,7 +416,7 @@ // lock on a mempool input, so we can use the return value of // CheckSequenceLocks to indicate the LockPoints validity. int maxInputHeight = 0; - for (int height : prevheights) { + for (const int height : prevheights) { // Can ignore mempool inputs since we'll fail if they had // non-zero locks. if (height != tip->nHeight + 1) { @@ -5017,7 +5017,7 @@ setDirtyBlockIndex.clear(); setDirtyFileInfo.clear(); - for (BlockMap::value_type &entry : mapBlockIndex) { + for (const BlockMap::value_type &entry : mapBlockIndex) { delete entry.second; } @@ -5267,7 +5267,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/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -43,7 +43,7 @@ static std::string EncodeDumpString(const std::string &str) { std::stringstream ret; - for (uint8_t c : str) { + for (const uint8_t c : str) { if (c <= 32 || c >= 128 || c == '%') { ret << '%' << HexStr(&c, &c + 1); } else { 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 @@ -1916,7 +1916,7 @@ } // Try to add wallet transactions to memory pool. - for (std::pair &item : mapSorted) { + for (const std::pair &item : mapSorted) { CWalletTx &wtx = *(item.second); CValidationState state; wtx.AcceptToMemoryPool(maxTxFee, state); @@ -2199,7 +2199,7 @@ mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx)); } - for (std::pair &item : mapSorted) { + for (const std::pair &item : mapSorted) { CWalletTx &wtx = *item.second; if (wtx.RelayWalletTransaction(connman)) { result.push_back(wtx.GetId()); @@ -2520,7 +2520,7 @@ AvailableCoins(availableCoins); - for (auto &coin : availableCoins) { + for (const auto &coin : availableCoins) { CTxDestination address; if (coin.fSpendable && ExtractDestination( @@ -3543,12 +3543,12 @@ LOCK(cs_wallet); WalletBatch batch(*database); - for (int64_t nIndex : setInternalKeyPool) { + for (const int64_t nIndex : setInternalKeyPool) { batch.ErasePool(nIndex); } setInternalKeyPool.clear(); - for (int64_t nIndex : setExternalKeyPool) { + for (const int64_t nIndex : setExternalKeyPool) { batch.ErasePool(nIndex); } setExternalKeyPool.clear(); @@ -3910,7 +3910,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); } @@ -3927,13 +3927,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; }