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/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/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..f256516e2c082 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -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..a6e362603aac5 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -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/mnauth.cpp b/src/evo/mnauth.cpp index 376c96ecfaf40..ab04c18d3e40f 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 a788bc22437fb..ba3a8ce8e2128 100644 --- a/src/evo/specialtxman.cpp +++ b/src/evo/specialtxman.cpp @@ -505,7 +505,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/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 0415a19d53776..fec6c4a6cd722 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/llmq/blockprocessor.cpp b/src/llmq/blockprocessor.cpp index 0baf23fb9abff..4fc57aba77de1 100644 --- a/src/llmq/blockprocessor.cpp +++ b/src/llmq/blockprocessor.cpp @@ -441,7 +441,7 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, gsl::no for (const auto& tx : block.vtx) { if (tx->nType == 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/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 dee9c08397dc7..33b84f56c756c 100644 --- a/src/masternode/meta.cpp +++ b/src/masternode/meta.cpp @@ -150,7 +150,7 @@ std::optional CMasternodeMetaMan::GetPlatformBan(const uint2 void CMasternodeMetaMan::RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg) { LOCK(cs); - m_seen_platform_bans.insert(inv_hash, std::move(msg)); + m_seen_platform_bans.emplace(inv_hash, std::move(msg)); } void CMasternodeMetaMan::AddUsedMasternode(const uint256& proTxHash) 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/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 12bd74cc79ddc..8f675c7336ab1 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/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/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..1a279b6bb74cf 100644 --- a/src/test/fuzz/txorphan.cpp +++ b/src/test/fuzz/txorphan.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -69,7 +68,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage) 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/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/script_tests.cpp b/src/test/script_tests.cpp index 06968ae7c5fd0..100f5300724cf 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -881,7 +881,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..9e83bdf6d3209 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering) } // 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/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