Skip to content

Commit ab0119c

Browse files
fanquakeknst
authored andcommitted
Merge bitcoin#25872: Fix issues when calling std::move(const&)
BACKPORT NOTE: Some missing changes for TRDescriptor and for mempool_args But they will be caugth by linter ---- fa87534 Fix iwyu (MacroFake) faad673 Fix issues when calling std::move(const&) (MacroFake) Pull request description: Passing a symbol to `std::move` that is marked `const` is a no-op, which can be fixed in two ways: * Remove the `const`, or * Remove the `std::move` ACKs for top commit: ryanofsky: Code review ACK fa87534. Looks good. Good for univalue to support c++11 move optimizations Tree-SHA512: 3dc5cad55b93cfa311abedfb811f35fc1b7f30a1c68561f15942438916c7de25e179c364be11881e01f844f9c2ccd71a3be55967ad5abd2f35b10bb7a882edea
1 parent 240fcfd commit ab0119c

File tree

16 files changed

+29
-27
lines changed

16 files changed

+29
-27
lines changed

ci/dash/lint-tidy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ iwyu_tool.py \
4444
"src/util/moneystr.cpp" \
4545
"src/util/serfloat.cpp" \
4646
"src/util/spanparsing.cpp" \
47+
"src/util/string.cpp" \
4748
"src/util/strencodings.cpp" \
4849
"src/util/syserror.cpp" \
4950
"src/util/url.cpp" \

src/.clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ misc-unused-using-decls,
66
modernize-use-default-member-init,
77
modernize-use-nullptr,
88
performance-for-range-copy,
9+
performance-move-const-arg,
910
performance-unnecessary-copy-initialization,
1011
readability-const-return-type,
1112
readability-redundant-declaration,
@@ -17,7 +18,11 @@ bugprone-use-after-move,
1718
misc-unused-using-decls,
1819
modernize-use-default-member-init,
1920
modernize-use-nullptr,
21+
performance-move-const-arg,
2022
performance-unnecessary-copy-initialization,
2123
readability-redundant-declaration,
2224
readability-redundant-string-init,
2325
'
26+
CheckOptions:
27+
- key: performance-move-const-arg.CheckTriviallyCopyableMove
28+
value: false

src/instantsend/instantsend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ instantsend::PendingState CInstantSendManager::ProcessPendingInstantSendLocks()
191191
removed.reserve(maxCount);
192192
pend.reserve(maxCount);
193193

194-
for (const auto& [islockHash, nodeid_islptr_pair] : pendingInstantSendLocks) {
194+
for (auto& [islockHash, nodeid_islptr_pair] : pendingInstantSendLocks) {
195195
// Check if we've reached max count
196196
if (pend.size() >= maxCount) {
197197
ret.m_pending_work = true;

src/llmq/blockprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, gsl::no
441441

442442
for (const auto& tx : block.vtx) {
443443
if (tx->nType == TRANSACTION_QUORUM_COMMITMENT) {
444-
const auto opt_qc = GetTxPayload<CFinalCommitmentTxPayload>(*tx);
444+
auto opt_qc = GetTxPayload<CFinalCommitmentTxPayload>(*tx);
445445
if (!opt_qc) {
446446
// should not happen as it was verified before processing the block
447447
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s height=%d GetTxPayload fails\n", __func__, pindex->nHeight);

src/masternode/meta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint2
150150
void CMasternodeMetaMan::RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg)
151151
{
152152
LOCK(cs);
153-
m_seen_platform_bans.insert(inv_hash, std::move(msg));
153+
m_seen_platform_bans.emplace(inv_hash, std::move(msg));
154154
}
155155

156156
void CMasternodeMetaMan::AddUsedMasternode(const uint256& proTxHash)

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,7 @@ static RPCHelpMan scantxoutset()
25272527
for (const UniValue& scanobject : request.params[1].get_array().getValues()) {
25282528
FlatSigningProvider provider;
25292529
auto scripts = EvalDescriptorStringOrObject(scanobject, provider);
2530-
for (const auto& script : scripts) {
2530+
for (CScript& script : scripts) {
25312531
std::string inferred = InferDescriptor(script, provider)->ToString();
25322532
needles.emplace(script);
25332533
descriptors.emplace(std::move(script), std::move(inferred));

src/script/descriptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ class DescriptorImpl : public Descriptor
547547
if (pos++) ret += ",";
548548
std::string tmp;
549549
if (!scriptarg->ToStringHelper(arg, tmp, type, cache)) return false;
550-
ret += std::move(tmp);
550+
ret += tmp;
551551
}
552552
return true;
553553
}
@@ -571,7 +571,7 @@ class DescriptorImpl : public Descriptor
571571
tmp = pubkey->ToString();
572572
break;
573573
}
574-
ret += std::move(tmp);
574+
ret += tmp;
575575
}
576576
std::string subscript;
577577
if (!ToStringSubScriptHelper(arg, subscript, type, cache)) return false;

src/test/fuzz/txorphan.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <util/check.h>
2020
#include <util/time.h>
2121

22-
#include <algorithm>
2322
#include <cstdint>
2423
#include <memory>
2524
#include <set>

src/univalue/include/univalue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ class UniValue {
7777
bool isArray() const { return (typ == VARR); }
7878
bool isObject() const { return (typ == VOBJ); }
7979

80-
void push_back(const UniValue& val);
80+
void push_back(UniValue val);
8181
void push_backV(const std::vector<UniValue>& vec);
8282
template <class It>
8383
void push_backV(It first, It last);
8484

85-
void __pushKV(const std::string& key, const UniValue& val);
86-
void pushKV(const std::string& key, const UniValue& val);
87-
void pushKVs(const UniValue& obj);
85+
void __pushKV(std::string key, UniValue val);
86+
void pushKV(std::string key, UniValue val);
87+
void pushKVs(UniValue obj);
8888

8989
std::string write(unsigned int prettyIndent = 0,
9090
unsigned int indentLevel = 0) const;

src/univalue/lib/univalue.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ void UniValue::setObject()
101101
typ = VOBJ;
102102
}
103103

104-
void UniValue::push_back(const UniValue& val_)
104+
void UniValue::push_back(UniValue val)
105105
{
106106
checkType(VARR);
107107

108-
values.push_back(val_);
108+
values.push_back(std::move(val));
109109
}
110110

111111
void UniValue::push_backV(const std::vector<UniValue>& vec)
@@ -115,32 +115,32 @@ void UniValue::push_backV(const std::vector<UniValue>& vec)
115115
values.insert(values.end(), vec.begin(), vec.end());
116116
}
117117

118-
void UniValue::__pushKV(const std::string& key, const UniValue& val_)
118+
void UniValue::__pushKV(std::string key, UniValue val)
119119
{
120120
checkType(VOBJ);
121121

122-
keys.push_back(key);
123-
values.push_back(val_);
122+
keys.push_back(std::move(key));
123+
values.push_back(std::move(val));
124124
}
125125

126-
void UniValue::pushKV(const std::string& key, const UniValue& val_)
126+
void UniValue::pushKV(std::string key, UniValue val)
127127
{
128128
checkType(VOBJ);
129129

130130
size_t idx;
131131
if (findKey(key, idx))
132-
values[idx] = val_;
132+
values[idx] = std::move(val);
133133
else
134-
__pushKV(key, val_);
134+
__pushKV(std::move(key), std::move(val));
135135
}
136136

137-
void UniValue::pushKVs(const UniValue& obj)
137+
void UniValue::pushKVs(UniValue obj)
138138
{
139139
checkType(VOBJ);
140140
obj.checkType(VOBJ);
141141

142142
for (size_t i = 0; i < obj.keys.size(); i++)
143-
__pushKV(obj.keys[i], obj.values.at(i));
143+
__pushKV(std::move(obj.keys.at(i)), std::move(obj.values.at(i)));
144144
}
145145

146146
void UniValue::getObjMap(std::map<std::string,UniValue>& kv) const

0 commit comments

Comments
 (0)