Merge bitcoin/bitcoin#25872: Fix issues when calling std::move(const&)

fa875349e2 Fix iwyu (MacroFake)
faad673716 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 fa875349e2. Looks good. Good for univalue to support c++11 move optimizations

Tree-SHA512: 3dc5cad55b93cfa311abedfb811f35fc1b7f30a1c68561f15942438916c7de25e179c364be11881e01f844f9c2ccd71a3be55967ad5abd2f35b10bb7a882edea
This commit is contained in:
fanquake 2022-08-31 08:32:25 +01:00
commit 01e1627e25
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
15 changed files with 28 additions and 27 deletions

View file

@ -65,6 +65,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
" src/util/serfloat.cpp"\
" src/util/spanparsing.cpp"\
" src/util/strencodings.cpp"\
" src/util/string.cpp"\
" src/util/syserror.cpp"\
" src/util/url.cpp"\
" -p . ${MAKEJOBS} -- -Xiwyu --cxx17ns -Xiwyu --mapping_file=${BASE_BUILD_DIR}/bitcoin-$HOST/contrib/devtools/iwyu/bitcoin.core.imp"

View file

@ -6,6 +6,7 @@ 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-redundant-declaration,
readability-redundant-string-init,
@ -17,7 +18,11 @@ 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-redundant-declaration,
readability-redundant-string-init,
'
CheckOptions:
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: false

View file

@ -12,6 +12,7 @@
#include <logging.h>
#include <policy/feerate.h>
#include <policy/policy.h>
#include <script/standard.h>
#include <tinyformat.h>
#include <util/error.h>
#include <util/moneystr.h>

View file

@ -2129,7 +2129,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));

View file

@ -572,7 +572,7 @@ public:
if (pos++) ret += ",";
std::string tmp;
if (!scriptarg->ToStringHelper(arg, tmp, type, cache)) return false;
ret += std::move(tmp);
ret += tmp;
}
return true;
}
@ -596,7 +596,7 @@ public:
tmp = pubkey->ToString();
break;
}
ret += std::move(tmp);
ret += tmp;
}
std::string subscript;
if (!ToStringSubScriptHelper(arg, subscript, type, cache)) return false;
@ -912,7 +912,7 @@ protected:
}
std::string tmp;
if (!m_subdescriptor_args[pos]->ToStringHelper(arg, tmp, type, cache)) return false;
ret += std::move(tmp);
ret += tmp;
while (!path.empty() && path.back()) {
if (path.size() > 1) ret += '}';
path.pop_back();

View file

@ -19,7 +19,6 @@
#include <util/check.h>
#include <util/time.h>
#include <algorithm>
#include <cstdint>
#include <memory>
#include <set>

View file

@ -6,6 +6,7 @@
#define BITCOIN_THREADINTERRUPT_H
#include <sync.h>
#include <threadsafety.h>
#include <atomic>
#include <chrono>

View file

@ -80,14 +80,14 @@ public:
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<UniValue>& vec);
template <class It>
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;

View file

@ -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<UniValue>& vec)
@ -115,32 +115,32 @@ void UniValue::push_backV(const std::vector<UniValue>& 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<std::string,UniValue>& kv) const

View file

@ -6,12 +6,10 @@
#include <util/bip32.h>
#include <util/strencodings.h>
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <sstream>
bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath)
{
std::stringstream ss(keypath_str);

View file

@ -8,7 +8,6 @@
#include <key_io.h>
#include <pubkey.h>
#include <script/standard.h>
#include <serialize.h>
#include <uint256.h>
#include <util/message.h>
#include <util/strencodings.h>

View file

@ -6,7 +6,6 @@
#include <span.h>
#include <util/strencodings.h>
#include <algorithm>
#include <array>
#include <cassert>
#include <cstring>

View file

@ -6,10 +6,9 @@
#include <regex>
#include <string>
#include <utility>
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute)
{
if (search.empty()) return;
in_out = std::regex_replace(in_out, std::regex(std::move(search)), substitute);
in_out = std::regex_replace(in_out, std::regex(search), substitute);
}

View file

@ -7,7 +7,6 @@
#include <util/spanparsing.h>
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstring>

View file

@ -353,7 +353,7 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
std::map<CTxDestination, std::vector<COutput>> result;
for (const COutput& coin : AvailableCoinsListUnspent(wallet).All()) {
for (COutput& coin : AvailableCoinsListUnspent(wallet).All()) {
CTxDestination address;
if ((coin.spendable || (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.solvable)) &&
ExtractDestination(FindNonChangeParentOutput(wallet, coin.outpoint).scriptPubKey, address)) {