diff --git a/ci/dash/lint-tidy.sh b/ci/dash/lint-tidy.sh index b186650db63ea..c4d9ab5ed431b 100755 --- a/ci/dash/lint-tidy.sh +++ b/ci/dash/lint-tidy.sh @@ -44,6 +44,7 @@ iwyu_tool.py \ "src/util/moneystr.cpp" \ "src/util/serfloat.cpp" \ "src/util/spanparsing.cpp" \ + "src/util/string.cpp" \ "src/util/strencodings.cpp" \ "src/util/syserror.cpp" \ "src/util/url.cpp" \ diff --git a/contrib/devtools/iwyu/bitcoin.core.imp b/contrib/devtools/iwyu/bitcoin.core.imp index 1f31229e0a48d..c4c4ba4cebd8e 100644 --- a/contrib/devtools/iwyu/bitcoin.core.imp +++ b/contrib/devtools/iwyu/bitcoin.core.imp @@ -1,3 +1,3 @@ -# Fixups / upstreamed changes +# Nothing for now. [ ] diff --git a/src/.clang-tidy b/src/.clang-tidy index 5ac5710613093..76978140ecd72 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -1,16 +1,28 @@ Checks: ' -*, bugprone-argument-comment, +bugprone-use-after-move, +misc-unused-using-decls, modernize-use-default-member-init, modernize-use-nullptr, +performance-for-range-copy, +performance-move-const-arg, +performance-unnecessary-copy-initialization, readability-const-return-type, readability-redundant-declaration, readability-redundant-string-init, ' WarningsAsErrors: ' bugprone-argument-comment, +bugprone-use-after-move, +misc-unused-using-decls, modernize-use-default-member-init, modernize-use-nullptr, +performance-move-const-arg, +performance-unnecessary-copy-initialization, readability-redundant-declaration, readability-redundant-string-init, ' +CheckOptions: + - key: performance-move-const-arg.CheckTriviallyCopyableMove + value: false diff --git a/src/bench/load_external.cpp b/src/bench/load_external.cpp index 68d7895f49b45..2d691484a3bda 100644 --- a/src/bench/load_external.cpp +++ b/src/bench/load_external.cpp @@ -28,7 +28,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench) // block data) as a stream object. const fs::path blkfile{testing_setup.get()->m_path_root / "blk.dat"}; CDataStream ss(SER_DISK, 0); - auto params{Params()}; + const auto& params{Params()}; ss << params.MessageStart(); ss << static_cast(benchmark::data::block813851.size()); // We can't use the streaming serialization (ss << benchmark::data::block813851) diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index 9ff4629741b30..8de8e05c067fe 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -112,6 +112,7 @@ static void PrevectorFillVectorDirect(benchmark::Bench& bench) { bench.run([&] { std::vector> vec; + vec.reserve(260); for (size_t i = 0; i < 260; ++i) { vec.emplace_back(); } @@ -124,6 +125,7 @@ static void PrevectorFillVectorIndirect(benchmark::Bench& bench) { bench.run([&] { std::vector> vec; + vec.reserve(260); for (size_t i = 0; i < 260; ++i) { // force allocation vec.emplace_back(29, T{}); diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp index 3d8700d5592ba..1a2bd7eceb326 100644 --- a/src/bench/wallet_loading.cpp +++ b/src/bench/wallet_loading.cpp @@ -19,8 +19,6 @@ using wallet::CWallet; using wallet::DatabaseFormat; using wallet::DatabaseOptions; -using wallet::ISMINE_SPENDABLE; -using wallet::MakeWalletDatabase; using wallet::TxStateInactive; using wallet::WALLET_FLAG_DESCRIPTORS; using wallet::WalletContext; diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 3e94ea5a26897..2f3b807131e99 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -948,7 +948,7 @@ static void GetWalletBalances(UniValue& result) UniValue balances(UniValue::VOBJ); for (const UniValue& wallet : wallets.getValues()) { - const std::string wallet_name = wallet.get_str(); + const std::string& wallet_name = wallet.get_str(); const UniValue getbalances = ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name); const UniValue& balance = getbalances.find_value("result")["mine"]["trusted"]; balances.pushKV(wallet_name, balance); diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 9c9ccdae59dcd..9951ca31a50fd 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -279,7 +279,7 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strIn CAmount value = ExtractAndValidateValue(vStrInputParts[0]); // extract and validate ADDRESS - std::string strAddr = vStrInputParts[1]; + const std::string& strAddr = vStrInputParts[1]; CTxDestination destination = DecodeDestination(strAddr); if (!IsValidDestination(destination)) { throw std::runtime_error("invalid TX output address"); @@ -311,7 +311,7 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str // Extract and validate FLAGS bool bScriptHash = false; if (vStrInputParts.size() == 3) { - std::string flags = vStrInputParts[2]; + const std::string& flags = vStrInputParts[2]; bScriptHash = (flags.find('S') != std::string::npos); } @@ -363,7 +363,7 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s // Extract FLAGS bool bScriptHash = false; if (vStrInputParts.size() == numkeys + 4) { - std::string flags = vStrInputParts.back(); + const std::string& flags = vStrInputParts.back(); bScriptHash = (flags.find('S') != std::string::npos); } else if (vStrInputParts.size() > numkeys + 4) { @@ -428,13 +428,13 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str CAmount value = ExtractAndValidateValue(vStrInputParts[0]); // extract and validate script - std::string strScript = vStrInputParts[1]; + const std::string& strScript = vStrInputParts[1]; CScript scriptPubKey = ParseScript(strScript); // Extract FLAGS bool bScriptHash = false; if (vStrInputParts.size() == 3) { - std::string flags = vStrInputParts.back(); + const std::string& flags = vStrInputParts.back(); bScriptHash = (flags.find('S') != std::string::npos); } @@ -555,7 +555,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) UniValue prevtxsObj = registers["prevtxs"]; { for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) { - UniValue prevOut = prevtxsObj[previdx]; + const UniValue& prevOut = prevtxsObj[previdx]; if (!prevOut.isObject()) throw std::runtime_error("expected prevtxs internal object"); diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp index f4638dabcc0d1..364ed1c7ec728 100644 --- a/src/blockfilter.cpp +++ b/src/blockfilter.cpp @@ -170,7 +170,7 @@ const std::set& AllBlockFilterTypes() static std::once_flag flag; std::call_once(flag, []() { - for (auto entry : g_filter_types) { + for (const auto& entry : g_filter_types) { types.insert(entry.first); } }); diff --git a/src/bls/bls_worker.cpp b/src/bls/bls_worker.cpp index 1a65899be450b..44f15e46c22b8 100644 --- a/src/bls/bls_worker.cpp +++ b/src/bls/bls_worker.cpp @@ -15,7 +15,7 @@ template bool VerifyVectorHelper(Span vec) { std::set set; - for (auto item : vec) { + for (const auto& item : vec) { if (!item.IsValid()) return false; // check duplicates diff --git a/src/coins.cpp b/src/coins.cpp index 0aa3bf708484b..d43e886b7603b 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -356,7 +356,7 @@ bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) cons try { return CCoinsViewBacked::GetCoin(outpoint, coin); } catch(const std::runtime_error& e) { - for (auto f : m_err_callbacks) { + for (const auto& f : m_err_callbacks) { f(); } LogPrintf("Error reading from database: %s\n", e.what()); diff --git a/src/core_read.cpp b/src/core_read.cpp index 9f7c198d3f9e2..b6753f9c12488 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -39,7 +39,7 @@ class OpCodeParser } mapOpNames[strName] = static_cast(op); // Convenience: OP_ADD and just ADD are both recognized: - if (strName.compare(0, 3, "OP_") == 0) { // strName starts with "OP_" + if (strName.starts_with("OP_")) { mapOpNames[strName.substr(3)] = static_cast(op); } } @@ -189,7 +189,7 @@ int ParseSighashString(const UniValue& sighash) {std::string("SINGLE"), int(SIGHASH_SINGLE)}, {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)}, }; - std::string strHashType = sighash.get_str(); + const std::string& strHashType = sighash.get_str(); const auto& it = map_sighash_values.find(strHashType); if (it != map_sighash_values.end()) { hash_type = it->second; diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index 7a82653b4bc51..772ac70630ac8 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -91,7 +91,7 @@ static std::optional GetCreditDataFromBlock(const gsl::n LogPrintf("%s: WARNING: No valid CbTx at height=%d\n", __func__, block_index->nHeight); return std::nullopt; } - for (CTransactionRef tx : block.vtx) { + for (const CTransactionRef& tx : block.vtx) { if (!tx->IsSpecialTxVersion() || tx->nType != TRANSACTION_ASSET_UNLOCK) continue; CAmount unlocked{0}; diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index cca3bb82b2b07..8ac189b8a612d 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -1836,7 +1836,7 @@ std::vector> CDeterministicMNManage temp_diffs.emplace_back(pIndex->GetBlockHash(), recalc_diff); // Move forward - current_list = std::move(next_list); + current_list = next_list; // TODO: make CDeterministicMNList moveable } // Verify that applying all diffs results in the target snapshot diff --git a/src/evo/mnauth.cpp b/src/evo/mnauth.cpp index 4d813ebbbf00f..caba4172e567e 100644 --- a/src/evo/mnauth.cpp +++ b/src/evo/mnauth.cpp @@ -36,9 +36,7 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternode if (Params().NetworkIDString() != CBaseChainParams::MAIN && gArgs.IsArgSet("-pushversion")) { nOurNodeVersion = gArgs.GetIntArg("-pushversion", PROTOCOL_VERSION); } - auto pk = mn_activeman.GetPubKey(); - const CBLSPublicKey pubKey(pk); - const uint256 signHash{::SerializeHash(std::make_tuple(pubKey, receivedMNAuthChallenge, peer.IsInboundConn(), nOurNodeVersion))}; + const uint256 signHash{::SerializeHash(std::make_tuple(mn_activeman.GetPubKey(), receivedMNAuthChallenge, peer.IsInboundConn(), nOurNodeVersion))}; mnauth.proRegTxHash = mn_activeman.GetProTxHash(); diff --git a/src/evo/specialtxman.cpp b/src/evo/specialtxman.cpp index f5bd3f810117a..33e1493331fae 100644 --- a/src/evo/specialtxman.cpp +++ b/src/evo/specialtxman.cpp @@ -191,17 +191,16 @@ bool CSpecialTxProcessor::RebuildListFromBlock(const CBlock& block, gsl::not_nul int nHeight = pindexPrev->nHeight + 1; - CDeterministicMNList oldList = prevList; - CDeterministicMNList newList = oldList; + CDeterministicMNList newList = prevList; newList.SetBlockHash(uint256()); // we can't know the final block hash, so better not return a (invalid) block hash newList.SetHeight(nHeight); - auto payee = oldList.GetMNPayee(pindexPrev); + auto payee = prevList.GetMNPayee(pindexPrev); - // we iterate the oldList here and update the newList + // we iterate the prevList here and update the newList // this is only valid as long these have not diverged at this point, which is the case as long as we don't add // code above this loop that modifies newList - oldList.ForEachMN(false, [&pindexPrev, &newList, this](auto& dmn) { + prevList.ForEachMN(false, [&pindexPrev, &newList, this](auto& dmn) { if (!dmn.pdmnState->confirmedHash.IsNull()) { // already confirmed return; @@ -503,7 +502,7 @@ bool CSpecialTxProcessor::RebuildListFromBlock(const CBlock& block, gsl::not_nul newList.UpdateMN(dmn.proTxHash, newState); }); - mnListRet = std::move(newList); + mnListRet = newList; return true; } diff --git a/src/governance/object.cpp b/src/governance/object.cpp index 01b9135d34c6a..173d2ab8db889 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -270,8 +270,8 @@ UniValue CGovernanceObject::GetJSONObject() const if (objResult.isObject()) { obj = objResult; } else { - std::vector arr1 = objResult.getValues(); - std::vector arr2 = arr1.at(0).getValues(); + const std::vector& arr1 = objResult.getValues(); + const std::vector& arr2 = arr1.at(0).getValues(); obj = arr2.at(1); } diff --git a/src/init.cpp b/src/init.cpp index 642df953f34f3..c831ed4986a81 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1440,7 +1440,7 @@ bool AppInitParameterInteraction(const ArgsManager& args) static bool LockDataDirectory(bool probeOnly) { // Make sure only a single Dash Core process is using the data directory. - fs::path datadir = gArgs.GetDataDirNet(); + const fs::path& datadir = gArgs.GetDataDirNet(); if (!DirIsWritable(datadir)) { return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), fs::PathToString(datadir))); } diff --git a/src/instantsend/instantsend.cpp b/src/instantsend/instantsend.cpp index 68766bf0c71fa..495eefd68119e 100644 --- a/src/instantsend/instantsend.cpp +++ b/src/instantsend/instantsend.cpp @@ -101,7 +101,7 @@ instantsend::PendingState CInstantSendManager::FetchPendingLocks() std::vector removed; removed.reserve(std::min(maxCount, pendingInstantSendLocks.size())); - for (const auto& [islockHash, nodeid_islptr_pair] : pendingInstantSendLocks) { + for (auto& [islockHash, nodeid_islptr_pair] : pendingInstantSendLocks) { // Check if we've reached max count if (ret.m_pending_is.size() >= maxCount) { ret.m_pending_work = true; diff --git a/src/instantsend/net_instantsend.cpp b/src/instantsend/net_instantsend.cpp index 0e4b4b38caf52..efd217c10d513 100644 --- a/src/instantsend/net_instantsend.cpp +++ b/src/instantsend/net_instantsend.cpp @@ -237,11 +237,11 @@ void NetInstantSend::ProcessPendingISLocks(std::vectornType == TRANSACTION_QUORUM_COMMITMENT) { - const auto opt_qc = GetTxPayload(*tx); + auto opt_qc = GetTxPayload(*tx); if (!opt_qc) { // should not happen as it was verified before processing the block LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s height=%d GetTxPayload fails\n", __func__, pindex->nHeight); diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index 43bc21af4af93..ff07837fafe60 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -1630,13 +1630,13 @@ void CSigSharesManager::SignPendingSigShares() auto opt_sigShare = CreateSigShare(*pQuorum, id, msgHash); if (opt_sigShare.has_value() && opt_sigShare->sigShare.Get().IsValid()) { - auto sigShare = *opt_sigShare; + auto& sigShare = *opt_sigShare; ProcessSigShare(sigShare, pQuorum); if (IsAllMembersConnectedEnabled(pQuorum->params.type, m_sporkman)) { LOCK(cs); auto& session = signedSessions[sigShare.GetSignHash()]; - session.sigShare = sigShare; + session.sigShare = std::move(sigShare); session.quorum = pQuorum; session.nextAttemptTime = 0; session.attempt = 0; diff --git a/src/llmq/snapshot.cpp b/src/llmq/snapshot.cpp index 123ad4c901941..cf744f6c781a4 100644 --- a/src/llmq/snapshot.cpp +++ b/src/llmq/snapshot.cpp @@ -209,17 +209,16 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan response.quorumSnapshotAtHMinus4C = std::move(snapshotHMinus4C.value()); } - CSimplifiedMNListDiff mn4c; if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus4CIndex, use_legacy_construction), - pWorkBlockHMinus4CIndex->GetBlockHash(), mn4c, errorRet)) { + pWorkBlockHMinus4CIndex->GetBlockHash(), response.mnListDiffAtHMinus4C, errorRet)) { + response.mnListDiffAtHMinus4C = {}; return false; } if (!use_legacy_construction) { baseBlockIndexes.push_back(pWorkBlockHMinus4CIndex); } - response.mnListDiffAtHMinus4C = std::move(mn4c); } else { response.extraShare = false; } diff --git a/src/logging.cpp b/src/logging.cpp index 293ac4463d347..d59d1a86aa9b6 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -462,7 +462,7 @@ void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& loggi } if (m_log_threadnames && m_started_new_line) { - const auto threadname = util::ThreadGetInternalName(); + const auto& threadname = util::ThreadGetInternalName(); // 16 chars total, "dash-" is 5 of them and another 1 is a NUL terminator str_prefixed.insert(0, "[" + strprintf("%10s", (threadname.empty() ? "unknown" : threadname)) + "] "); } diff --git a/src/masternode/meta.cpp b/src/masternode/meta.cpp index 226aefb59f63a..48d106b968da5 100644 --- a/src/masternode/meta.cpp +++ b/src/masternode/meta.cpp @@ -202,7 +202,7 @@ bool CMasternodeMetaMan::SetPlatformBan(const uint256& inv_hash, PlatformBanMess bool ret = GetMetaInfo(protx_hash).SetPlatformBan(true, ban_msg.m_requested_height); if (ret) { - m_seen_platform_bans.insert(inv_hash, std::move(ban_msg)); + m_seen_platform_bans.emplace(inv_hash, std::move(ban_msg)); } return ret; } diff --git a/src/netbase.cpp b/src/netbase.cpp index 7ac84ad4e3d0e..b1a4f77500768 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -390,7 +390,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a return error("Error sending to proxy"); } uint8_t pchRet1[2]; - if ((recvr = InterruptibleRecv(pchRet1, 2, g_socks5_recv_timeout, sock)) != IntrRecvError::OK) { + if (InterruptibleRecv(pchRet1, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) { LogPrintf("Socks5() connect to %s:%d failed: InterruptibleRecv() timeout or other failure\n", strDest, port); return false; } @@ -413,7 +413,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a } LogPrint(BCLog::PROXY, "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password); uint8_t pchRetA[2]; - if ((recvr = InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock)) != IntrRecvError::OK) { + if (InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) { return error("Error reading proxy authentication response"); } if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) { @@ -479,7 +479,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a if (recvr != IntrRecvError::OK) { return error("Error reading from proxy"); } - if ((recvr = InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock)) != IntrRecvError::OK) { + if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) { return error("Error reading from proxy"); } LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest); diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 707acd044c289..76fd09843ac71 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -448,7 +448,7 @@ void CleanupBlockRevFiles() // Remove the rev files immediately and insert the blk file paths into an // ordered map keyed by block file index. LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n"); - fs::path blocksdir = gArgs.GetBlocksDirPath(); + const fs::path& blocksdir = gArgs.GetBlocksDirPath(); for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) { const std::string path = fs::PathToString(it->path().filename()); if (fs::is_regular_file(*it) && diff --git a/src/qt/bitcoinunits.cpp b/src/qt/bitcoinunits.cpp index 2d5d6d265f62b..65ddc1bda5f86 100644 --- a/src/qt/bitcoinunits.cpp +++ b/src/qt/bitcoinunits.cpp @@ -182,7 +182,7 @@ bool BitcoinUnits::parse(Unit unit, const QString& value, CAmount* val_out) { return false; // More than one dot } - QString whole = parts[0]; + const QString& whole = parts[0]; QString decimals; if(parts.size() > 1) diff --git a/src/qt/governancelist.cpp b/src/qt/governancelist.cpp index 49c6abe6e6289..37f61fca4a066 100644 --- a/src/qt/governancelist.cpp +++ b/src/qt/governancelist.cpp @@ -43,23 +43,23 @@ Proposal::Proposal(ClientModel* _clientModel, const CGovernanceObject& _govObj, { UniValue prop_data; if (prop_data.read(govObj.GetDataAsPlainString())) { - if (UniValue titleValue = prop_data.find_value("name"); titleValue.isStr()) { + if (const UniValue& titleValue = prop_data.find_value("name"); titleValue.isStr()) { m_title = QString::fromStdString(titleValue.get_str()); } - if (UniValue paymentStartValue = prop_data.find_value("start_epoch"); paymentStartValue.isNum()) { + if (const UniValue& paymentStartValue = prop_data.find_value("start_epoch"); paymentStartValue.isNum()) { m_startDate = QDateTime::fromSecsSinceEpoch(paymentStartValue.getInt()); } - if (UniValue paymentEndValue = prop_data.find_value("end_epoch"); paymentEndValue.isNum()) { + if (const UniValue& paymentEndValue = prop_data.find_value("end_epoch"); paymentEndValue.isNum()) { m_endDate = QDateTime::fromSecsSinceEpoch(paymentEndValue.getInt()); } - if (UniValue amountValue = prop_data.find_value("payment_amount"); amountValue.isNum()) { + if (const UniValue& amountValue = prop_data.find_value("payment_amount"); amountValue.isNum()) { m_paymentAmount = amountValue.get_real(); } - if (UniValue urlValue = prop_data.find_value("url"); urlValue.isStr()) { + if (const UniValue& urlValue = prop_data.find_value("url"); urlValue.isStr()) { m_url = QString::fromStdString(urlValue.get_str()); } } diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index cb92b6d9e2f54..f82f71c2c2647 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -55,7 +55,7 @@ SplashScreen::SplashScreen(const NetworkStyle *networkStyle) : // define text to place QString titleText = PACKAGE_NAME; QString versionText = QString::fromStdString(FormatFullVersion()).remove(0, 1); - QString titleAddText = networkStyle->getTitleAddText(); + const QString& titleAddText = networkStyle->getTitleAddText(); QFont fontNormal = GUIUtil::getFontNormal(); QFont fontBold = GUIUtil::getFontBold(); @@ -116,8 +116,7 @@ SplashScreen::SplashScreen(const NetworkStyle *networkStyle) : int titleAddTextWidth = GUIUtil::TextWidth(fm, titleAddText); // Draw the badge background with the network-specific color QRect badgeRect = QRect(width - titleAddTextWidth - 20, 5, width, fm.height() + 10); - QColor badgeColor = networkStyle->getBadgeColor(); - pixPaint.fillRect(badgeRect, badgeColor); + pixPaint.fillRect(badgeRect, networkStyle->getBadgeColor()); // Draw the text itself using white color, regardless of the current theme pixPaint.setPen(QColor(255, 255, 255)); pixPaint.drawText(width - titleAddTextWidth - 10, paddingTop + 10, titleAddText); diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 0e550eb1bf9e3..3814cd9c19999 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -13,7 +13,6 @@ #include -using wallet::ISMINE_ALL; using wallet::ISMINE_SPENDABLE; using wallet::ISMINE_WATCH_ONLY; using wallet::isminetype; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index fbb893e637f2f..8401e186c750f 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2527,7 +2527,7 @@ static RPCHelpMan scantxoutset() for (const UniValue& scanobject : request.params[1].get_array().getValues()) { FlatSigningProvider provider; auto scripts = EvalDescriptorStringOrObject(scanobject, provider); - for (const auto& script : scripts) { + for (CScript& script : scripts) { std::string inferred = InferDescriptor(script, provider)->ToString(); needles.emplace(script); descriptors.emplace(std::move(script), std::move(inferred)); diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index 0c9b16bd634bf..d3dd399dd35d4 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -173,7 +173,7 @@ static RPCHelpMan coinjoin_status() } UniValue ret(UniValue::VARR); - for (auto str_status : cj_clientman->getSessionStatuses()) { + for (const auto& str_status : cj_clientman->getSessionStatuses()) { ret.push_back(str_status); } return ret; diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index da14a2de4cac3..44c6f4fda664d 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -50,8 +50,6 @@ using node::NodeContext; using wallet::CWallet; #ifdef ENABLE_WALLET using wallet::CCoinControl; -using wallet::CoinType; -using wallet::COutput; using wallet::CRecipient; using wallet::DEFAULT_DISABLE_WALLET; using wallet::GetWalletForJSONRPCRequest; diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 3ea189ebbc28a..7a8537da33563 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -36,7 +36,6 @@ using node::ReadBlockFromDisk; #ifdef ENABLE_WALLET using wallet::CCoinControl; using wallet::CoinType; -using wallet::COutput; using wallet::CWallet; using wallet::GetWalletForJSONRPCRequest; #endif // ENABLE_WALLET diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 11e6cd906d451..6e372c75cea03 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -131,7 +131,7 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& block_hash.SetNull(); block.hashMerkleRoot = BlockMerkleRoot(block); - CChainParams chainparams(Params()); + const CChainParams& chainparams(Params()); while (max_tries > 0 && block.nNonce < std::numeric_limits::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus()) && !ShutdownRequested()) { ++block.nNonce; @@ -356,7 +356,7 @@ static RPCHelpMan generateblock() } } - CChainParams chainparams(Params()); + const CChainParams& chainparams(Params()); const LLMQContext& llmq_ctx = EnsureLLMQContext(node); ChainstateManager& chainman = EnsureChainman(node); @@ -755,7 +755,7 @@ static RPCHelpMan getblocktemplate() if (lpval.isStr()) { // Format: - std::string lpstr = lpval.get_str(); + const std::string& lpstr = lpval.get_str(); hashWatchedChain = ParseHashV(lpstr.substr(0, 64), "longpollid"); nTransactionsUpdatedLastLP = LocaleIndependentAtoi(lpstr.substr(64)); diff --git a/src/rpc/output_script.cpp b/src/rpc/output_script.cpp index ad26dd77c168f..ca5beef1d0f71 100644 --- a/src/rpc/output_script.cpp +++ b/src/rpc/output_script.cpp @@ -23,11 +23,6 @@ #include #include -namespace node { -struct NodeContext; -} -using node::NodeContext; - static RPCHelpMan validateaddress() { return RPCHelpMan{ diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp index e66a5b2d3aa94..8ab727004650a 100644 --- a/src/rpc/rawtransaction_util.cpp +++ b/src/rpc/rawtransaction_util.cpp @@ -146,14 +146,14 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std:: void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keystore, std::map& coins) { if (!prevTxsUnival.isNull()) { - UniValue prevTxs = prevTxsUnival.get_array(); + const UniValue& prevTxs = prevTxsUnival.get_array(); for (unsigned int idx = 0; idx < prevTxs.size(); ++idx) { const UniValue& p = prevTxs[idx]; if (!p.isObject()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}"); } - UniValue prevOut = p.get_obj(); + const UniValue& prevOut = p.get_obj(); RPCTypeCheckObj(prevOut, { diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index da552c410f5f4..3f3b852422f19 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -99,7 +99,7 @@ CAmount AmountFromValue(const UniValue& value, int decimals) uint256 ParseHashV(const UniValue& v, std::string strName) { - std::string strHex{v.get_str()}; + const std::string& strHex(v.get_str()); if (64 != strHex.length()) throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be of length %d (not %d, for '%s')", strName, 64, strHex.length(), strHex)); if (!IsHex(strHex)) // Note: IsHex("") is false @@ -126,7 +126,7 @@ std::vector ParseHexO(const UniValue& o, std::string strKey) int32_t ParseInt32V(const UniValue& v, const std::string &strName) { - std::string strNum = v.getValStr(); + const std::string& strNum = v.getValStr(); int32_t num; if (!ParseInt32(strNum, &num)) throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a 32bit integer (not '"+strNum+"')"); @@ -135,7 +135,7 @@ int32_t ParseInt32V(const UniValue& v, const std::string &strName) int64_t ParseInt64V(const UniValue& v, const std::string &strName) { - std::string strNum = v.getValStr(); + const std::string& strNum = v.getValStr(); int64_t num; if (!ParseInt64(strNum, &num)) throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a 64bit integer (not '"+strNum+"')"); diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 1b84c6f580e89..49d14db91562d 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -547,7 +547,7 @@ class DescriptorImpl : public Descriptor if (pos++) ret += ","; std::string tmp; if (!scriptarg->ToStringHelper(arg, tmp, type, cache)) return false; - ret += std::move(tmp); + ret += tmp; } return true; } @@ -571,7 +571,7 @@ class DescriptorImpl : public Descriptor tmp = pubkey->ToString(); break; } - ret += std::move(tmp); + ret += tmp; } std::string subscript; if (!ToStringSubScriptHelper(arg, subscript, type, cache)) return false; diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index fbe873ef3237a..2cd1ae9510d2a 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(base58_EncodeBase58) { UniValue tests = read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode + sizeof(json_tests::base58_encode_decode))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test.size() < 2) // Allow for extra stuff (useful for comments) { @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(base58_DecodeBase58) std::vector result; for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test.size() < 2) // Allow for extra stuff (useful for comments) { diff --git a/src/test/blockfilter_tests.cpp b/src/test/blockfilter_tests.cpp index 54ab568e7d3a0..b33cca1377384 100644 --- a/src/test/blockfilter_tests.cpp +++ b/src/test/blockfilter_tests.cpp @@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(blockfilters_json_test) const UniValue& tests = json.get_array(); for (unsigned int i = 0; i < tests.size(); i++) { - UniValue test = tests[i]; + const UniValue& test = tests[i]; std::string strTest = test.write(); if (test.size() == 1) { diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index cd816f943c4d1..a73b4c252642c 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -384,6 +384,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) auto queue = std::make_unique(QUEUE_BATCH_SIZE); { std::vector tg; + tg.reserve(3); std::atomic nThreads {0}; std::atomic fails {0}; for (size_t i = 0; i < 3; ++i) { diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index c11a0b57538e7..793c2d84a1796 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -761,10 +761,10 @@ static void CheckAddCoinBase(CAmount base_value, CAmount cache_value, CAmount mo // while still verifying that the CoinsViewCache::AddCoin implementation // ignores base values. template -static void CheckAddCoin(Args&&... args) +static void CheckAddCoin(const Args&... args) { for (const CAmount base_value : {ABSENT, SPENT, VALUE1}) - CheckAddCoinBase(base_value, std::forward(args)...); + CheckAddCoinBase(base_value, args...); } BOOST_AUTO_TEST_CASE(ccoins_add) diff --git a/src/test/coinstatsindex_tests.cpp b/src/test/coinstatsindex_tests.cpp index e3335373231f9..b8f5a2b4b9f0f 100644 --- a/src/test/coinstatsindex_tests.cpp +++ b/src/test/coinstatsindex_tests.cpp @@ -12,9 +12,6 @@ #include -using kernel::CCoinsStats; -using kernel::CoinStatsHashType; - BOOST_AUTO_TEST_SUITE(coinstatsindex_tests) BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) diff --git a/src/test/cuckoocache_tests.cpp b/src/test/cuckoocache_tests.cpp index c9d1202b58fe4..ea5c81a3bcc86 100644 --- a/src/test/cuckoocache_tests.cpp +++ b/src/test/cuckoocache_tests.cpp @@ -219,6 +219,7 @@ static void test_cache_erase_parallel(size_t megabytes) /** Spin up 3 threads to run contains with erase. */ std::vector threads; + threads.reserve(3); /** Erase the first quarter */ for (uint32_t x = 0; x < 3; ++x) /** Each thread is emplaced with x copy-by-value diff --git a/src/test/evo_deterministicmns_tests.cpp b/src/test/evo_deterministicmns_tests.cpp index c67d4dd407258..8d27e75aec0ff 100644 --- a/src/test/evo_deterministicmns_tests.cpp +++ b/src/test/evo_deterministicmns_tests.cpp @@ -886,8 +886,9 @@ static void SmlCache(TestChainSetup& setup) CDeterministicMNList mn_list_1(emptyList); BOOST_CHECK(sml_empty == mn_list_1.to_sml()); + CDeterministicMNList mn_list_2; // Assigning list should return the same cached object - CDeterministicMNList mn_list_2 = emptyList; + mn_list_2 = emptyList; BOOST_CHECK(sml_empty == mn_list_2.to_sml()); auto dmn = create_mock_mn(1); diff --git a/src/test/evo_trivialvalidation.cpp b/src/test/evo_trivialvalidation.cpp index 55312417d9ef1..df076eadca219 100644 --- a/src/test/evo_trivialvalidation.cpp +++ b/src/test/evo_trivialvalidation.cpp @@ -48,7 +48,7 @@ void trivialvalidation_runner(const CChain& active_chain, const std::string& jso const UniValue vectors = read_json(json); for (size_t idx = 1; idx < vectors.size(); idx++) { - UniValue test = vectors[idx]; + const UniValue& test = vectors[idx]; uint256 txHash; std::string txType; CMutableTransaction tx; diff --git a/src/test/fuzz/txorphan.cpp b/src/test/fuzz/txorphan.cpp index 25244771dfa95..f4d12c41fce4a 100644 --- a/src/test/fuzz/txorphan.cpp +++ b/src/test/fuzz/txorphan.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -66,10 +65,11 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage) } } // output amount will not affect txorphanage + tx_mut.vout.reserve(num_out); for (uint32_t i = 0; i < num_out; i++) { tx_mut.vout.emplace_back(CAmount{0}, CScript{}); } - // restore previously poped outpoints + // restore previously popped outpoints for (auto& in : tx_mut.vin) { outpoints.push_back(in.prevout); } diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index 0f505cc794394..ea008b8f50ffb 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -147,6 +147,7 @@ template { const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange(0, max_vector_size); std::vector r; + r.reserve(n_elements); for (size_t i = 0; i < n_elements; ++i) { r.push_back(fuzzed_data_provider.ConsumeRandomLengthString(max_string_length)); } @@ -158,6 +159,7 @@ template { const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange(0, max_vector_size); std::vector r; + r.reserve(n_elements); for (size_t i = 0; i < n_elements; ++i) { r.push_back(fuzzed_data_provider.ConsumeIntegral()); } diff --git a/src/test/key_io_tests.cpp b/src/test/key_io_tests.cpp index d01e4cb6fbe7c..827c6cc71e189 100644 --- a/src/test/key_io_tests.cpp +++ b/src/test/key_io_tests.cpp @@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse) SelectParams(CBaseChainParams::MAIN); for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test.size() < 3) { // Allow for extra stuff (useful for comments) BOOST_ERROR("Bad test: " << strTest); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_gen) UniValue tests = read_json(std::string(json_tests::key_io_valid, json_tests::key_io_valid + sizeof(json_tests::key_io_valid))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test.size() < 3) // Allow for extra stuff (useful for comments) { @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(key_io_invalid) CTxDestination destination; for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test.size() < 1) // Allow for extra stuff (useful for comments) { diff --git a/src/test/miniscript_tests.cpp b/src/test/miniscript_tests.cpp index 3877fea907e88..46ed47b1d4803 100644 --- a/src/test/miniscript_tests.cpp +++ b/src/test/miniscript_tests.cpp @@ -116,6 +116,8 @@ struct KeyConverter { //! Singleton instance of KeyConverter. const KeyConverter CONVERTER{}; +// https://github.com/llvm/llvm-project/issues/53444 +// NOLINTNEXTLINE(misc-unused-using-decls) using miniscript::operator"" _mst; enum TestMode : int { diff --git a/src/test/result_tests.cpp b/src/test/result_tests.cpp index 6a23a7b8950a9..2df756992b05d 100644 --- a/src/test/result_tests.cpp +++ b/src/test/result_tests.cpp @@ -63,7 +63,8 @@ void ExpectSuccess(const util::Result& result, const bilingual_str& str, Args { ExpectResult(result, true, str); BOOST_CHECK_EQUAL(result.has_value(), true); - BOOST_CHECK_EQUAL(result.value(), T{std::forward(args)...}); + T expected{std::forward(args)...}; + BOOST_CHECK_EQUAL(result.value(), expected); BOOST_CHECK_EQUAL(&result.value(), &*result); } diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 4809b859bee6c..6ebc56e250e1a 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -441,6 +441,7 @@ BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_size) { int64_t total_size = 200; std::vector> feerates; + feerates.reserve(200); CAmount result[NUM_GETBLOCKSTATS_PERCENTILES] = { 0 }; for (int64_t i = 0; i < 100; i++) { diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 06968ae7c5fd0..4924c26e0af05 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -113,8 +113,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, uint32_t flag bool expect = (scriptError == SCRIPT_ERR_OK); ScriptError err; const CTransaction txCredit{BuildCreditingTransaction(scriptPubKey)}; - CMutableTransaction tx = BuildSpendingTransaction(scriptSig, txCredit); - CMutableTransaction tx2 = tx; + const CMutableTransaction tx = BuildSpendingTransaction(scriptSig, txCredit); BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue, MissingDataBehavior::ASSERT_FAIL), &err) == expect, message); BOOST_CHECK_MESSAGE(err == scriptError, FormatScriptError(err) + " where " + FormatScriptError((ScriptError_t)scriptError) + " expected: " + message); @@ -129,7 +128,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, uint32_t flag #if defined(HAVE_CONSENSUS_LIB) CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); - stream << tx2; + stream << tx; uint32_t libconsensus_flags{flags & dashconsensus_SCRIPT_FLAGS_VERIFY_ALL}; if (libconsensus_flags == flags) { int expectedSuccessCode = expect ? 1 : 0; @@ -881,7 +880,7 @@ BOOST_AUTO_TEST_CASE(script_json_test) UniValue tests = read_json(std::string(json_tests::script_tests, json_tests::script_tests + sizeof(json_tests::script_tests))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test.size() < 4) // Allow size > 3; extra stuff ignored (useful for comments) { diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index 2a62c16c90d4c..f1d8e6d0ad909 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(sighash_from_data) UniValue tests = read_json(std::string(json_tests::sighash, json_tests::sighash + sizeof(json_tests::sighash))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test.size() < 1) // Allow for extra stuff (useful for comments) { diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 5a61438d9dd0d..6e117ad5117b9 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(tx_valid) UniValue tests = read_json(std::string(json_tests::tx_valid, json_tests::tx_valid + sizeof(json_tests::tx_valid))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test[0].isArray()) { @@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(tx_valid) fValid = false; break; } - UniValue vinput = input.get_array(); + const UniValue& vinput = input.get_array(); if (vinput.size() != 3) { fValid = false; @@ -237,7 +237,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid) UniValue tests = read_json(std::string(json_tests::tx_invalid, json_tests::tx_invalid + sizeof(json_tests::tx_invalid))); for (unsigned int idx = 0; idx < tests.size(); idx++) { - UniValue test = tests[idx]; + const UniValue& test = tests[idx]; std::string strTest = test.write(); if (test[0].isArray()) { @@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid) fValid = false; break; } - UniValue vinput = input.get_array(); + const UniValue& vinput = input.get_array(); if (vinput.size() != 3) { fValid = false; diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index ae2778ac56904..6d5c7be2c019c 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1304,13 +1304,13 @@ BOOST_AUTO_TEST_CASE(test_tracked_vector) auto v2 = Vector(std::move(t2)); BOOST_CHECK_EQUAL(v2.size(), 1U); - BOOST_CHECK(v2[0].origin == &t2); + BOOST_CHECK(v2[0].origin == &t2); // NOLINT(*-use-after-move) BOOST_CHECK_EQUAL(v2[0].copies, 0); auto v3 = Vector(t1, std::move(t2)); BOOST_CHECK_EQUAL(v3.size(), 2U); BOOST_CHECK(v3[0].origin == &t1); - BOOST_CHECK(v3[1].origin == &t2); + BOOST_CHECK(v3[1].origin == &t2); // NOLINT(*-use-after-move) BOOST_CHECK_EQUAL(v3[0].copies, 1); BOOST_CHECK_EQUAL(v3[1].copies, 0); @@ -1318,7 +1318,7 @@ BOOST_AUTO_TEST_CASE(test_tracked_vector) BOOST_CHECK_EQUAL(v4.size(), 3U); BOOST_CHECK(v4[0].origin == &t1); BOOST_CHECK(v4[1].origin == &t2); - BOOST_CHECK(v4[2].origin == &t3); + BOOST_CHECK(v4[2].origin == &t3); // NOLINT(*-use-after-move) BOOST_CHECK_EQUAL(v4[0].copies, 1); BOOST_CHECK_EQUAL(v4[1].copies, 1); BOOST_CHECK_EQUAL(v4[2].copies, 0); diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index 99a6109fee68c..280908c8d558a 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -177,12 +177,12 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering) bool ignored; FastRandomContext insecure; for (int i = 0; i < 1000; i++) { - auto block = blocks[insecure.randrange(blocks.size() - 1)]; + const auto& block = blocks[insecure.randrange(blocks.size() - 1)]; Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored); } // to make sure that eventually we process the full chain - do it here - for (auto block : blocks) { + for (const auto& block : blocks) { if (block->vtx.size() == 1) { bool processed = Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored); assert(processed); diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 50c01a4d718a3..67958c521596f 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -350,7 +350,7 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe std::string socks_location; if (reply.code == 250) { for (const auto& line : reply.lines) { - if (0 == line.compare(0, 20, "net/listeners/socks=")) { + if (line.starts_with("net/listeners/socks=")) { const std::string port_list_str = line.substr(20); std::vector port_list = SplitString(port_list_str, ' '); @@ -361,7 +361,7 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe if (portstr.empty()) continue; } socks_location = portstr; - if (0 == portstr.compare(0, 10, "127.0.0.1:")) { + if (portstr.starts_with("127.0.0.1:")) { // Prefer localhost - ignore other ports break; } diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index 076fcfa43277f..d895b26af988b 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -77,14 +77,14 @@ class UniValue { bool isArray() const { return (typ == VARR); } bool isObject() const { return (typ == VOBJ); } - void push_back(const UniValue& val); + void push_back(UniValue val); void push_backV(const std::vector& vec); template void push_backV(It first, It last); - void __pushKV(const std::string& key, const UniValue& val); - void pushKV(const std::string& key, const UniValue& val); - void pushKVs(const UniValue& obj); + void __pushKV(std::string key, UniValue val); + void pushKV(std::string key, UniValue val); + void pushKVs(UniValue obj); std::string write(unsigned int prettyIndent = 0, unsigned int indentLevel = 0) const; diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp index 4c8066767a94e..29660ceedc466 100644 --- a/src/univalue/lib/univalue.cpp +++ b/src/univalue/lib/univalue.cpp @@ -101,11 +101,11 @@ void UniValue::setObject() typ = VOBJ; } -void UniValue::push_back(const UniValue& val_) +void UniValue::push_back(UniValue val) { checkType(VARR); - values.push_back(val_); + values.push_back(std::move(val)); } void UniValue::push_backV(const std::vector& vec) @@ -115,32 +115,32 @@ void UniValue::push_backV(const std::vector& vec) values.insert(values.end(), vec.begin(), vec.end()); } -void UniValue::__pushKV(const std::string& key, const UniValue& val_) +void UniValue::__pushKV(std::string key, UniValue val) { checkType(VOBJ); - keys.push_back(key); - values.push_back(val_); + keys.push_back(std::move(key)); + values.push_back(std::move(val)); } -void UniValue::pushKV(const std::string& key, const UniValue& val_) +void UniValue::pushKV(std::string key, UniValue val) { checkType(VOBJ); size_t idx; if (findKey(key, idx)) - values[idx] = val_; + values[idx] = std::move(val); else - __pushKV(key, val_); + __pushKV(std::move(key), std::move(val)); } -void UniValue::pushKVs(const UniValue& obj) +void UniValue::pushKVs(UniValue obj) { checkType(VOBJ); obj.checkType(VOBJ); for (size_t i = 0; i < obj.keys.size(); i++) - __pushKV(obj.keys[i], obj.values.at(i)); + __pushKV(std::move(obj.keys.at(i)), std::move(obj.values.at(i))); } void UniValue::getObjMap(std::map& kv) const diff --git a/src/util/message.cpp b/src/util/message.cpp index 685093bb12da0..2a723b3bf2085 100644 --- a/src/util/message.cpp +++ b/src/util/message.cpp @@ -8,7 +8,6 @@ #include #include #include