Merge bitcoin/bitcoin#26935: refactor: Fix clang-tidy readability-const-return-type violations

fa451d4b60 Fix clang-tidy readability-const-return-type violations (MarcoFalke)

Pull request description:

  This comes up during review, so instead of wasting review cycles on this, just enforce it via CI

ACKs for top commit:
  stickies-v:
    utACK fa451d4b6
  hebasto:
    ACK fa451d4b60.

Tree-SHA512: 144a85612f00ec43f7ea1fdaa11901ca981a9f0465a8849745712d741b201b9c3307118172ee0b8efd12bebf25bc6f32a6e2c908495e371f9ada0a917994f44e
This commit is contained in:
fanquake 2023-02-01 15:49:54 +00:00
commit 550e6bd227
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
25 changed files with 54 additions and 52 deletions

View file

@ -9,6 +9,7 @@ performance-for-range-copy,
performance-move-const-arg, performance-move-const-arg,
performance-no-automatic-move, performance-no-automatic-move,
performance-unnecessary-copy-initialization, performance-unnecessary-copy-initialization,
readability-const-return-type,
readability-redundant-declaration, readability-redundant-declaration,
readability-redundant-string-init, readability-redundant-string-init,
' '

View file

@ -58,7 +58,7 @@ public:
explicit base_uint(const std::string& str); explicit base_uint(const std::string& str);
const base_uint operator~() const base_uint operator~() const
{ {
base_uint ret; base_uint ret;
for (int i = 0; i < WIDTH; i++) for (int i = 0; i < WIDTH; i++)
@ -66,7 +66,7 @@ public:
return ret; return ret;
} }
const base_uint operator-() const base_uint operator-() const
{ {
base_uint ret; base_uint ret;
for (int i = 0; i < WIDTH; i++) for (int i = 0; i < WIDTH; i++)
@ -171,7 +171,7 @@ public:
return *this; return *this;
} }
const base_uint operator++(int) base_uint operator++(int)
{ {
// postfix operator // postfix operator
const base_uint ret = *this; const base_uint ret = *this;
@ -188,7 +188,7 @@ public:
return *this; return *this;
} }
const base_uint operator--(int) base_uint operator--(int)
{ {
// postfix operator // postfix operator
const base_uint ret = *this; const base_uint ret = *this;
@ -199,16 +199,16 @@ public:
int CompareTo(const base_uint& b) const; int CompareTo(const base_uint& b) const;
bool EqualTo(uint64_t b) const; bool EqualTo(uint64_t b) const;
friend inline const base_uint operator+(const base_uint& a, const base_uint& b) { return base_uint(a) += b; } friend inline base_uint operator+(const base_uint& a, const base_uint& b) { return base_uint(a) += b; }
friend inline const base_uint operator-(const base_uint& a, const base_uint& b) { return base_uint(a) -= b; } friend inline base_uint operator-(const base_uint& a, const base_uint& b) { return base_uint(a) -= b; }
friend inline const base_uint operator*(const base_uint& a, const base_uint& b) { return base_uint(a) *= b; } friend inline base_uint operator*(const base_uint& a, const base_uint& b) { return base_uint(a) *= b; }
friend inline const base_uint operator/(const base_uint& a, const base_uint& b) { return base_uint(a) /= b; } friend inline base_uint operator/(const base_uint& a, const base_uint& b) { return base_uint(a) /= b; }
friend inline const base_uint operator|(const base_uint& a, const base_uint& b) { return base_uint(a) |= b; } friend inline base_uint operator|(const base_uint& a, const base_uint& b) { return base_uint(a) |= b; }
friend inline const base_uint operator&(const base_uint& a, const base_uint& b) { return base_uint(a) &= b; } friend inline base_uint operator&(const base_uint& a, const base_uint& b) { return base_uint(a) &= b; }
friend inline const base_uint operator^(const base_uint& a, const base_uint& b) { return base_uint(a) ^= b; } friend inline base_uint operator^(const base_uint& a, const base_uint& b) { return base_uint(a) ^= b; }
friend inline const base_uint operator>>(const base_uint& a, int shift) { return base_uint(a) >>= shift; } friend inline base_uint operator>>(const base_uint& a, int shift) { return base_uint(a) >>= shift; }
friend inline const base_uint operator<<(const base_uint& a, int shift) { return base_uint(a) <<= shift; } friend inline base_uint operator<<(const base_uint& a, int shift) { return base_uint(a) <<= shift; }
friend inline const base_uint operator*(const base_uint& a, uint32_t b) { return base_uint(a) *= b; } friend inline base_uint operator*(const base_uint& a, uint32_t b) { return base_uint(a) *= b; }
friend inline bool operator==(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) == 0; } friend inline bool operator==(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) == 0; }
friend inline bool operator!=(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) != 0; } friend inline bool operator!=(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) != 0; }
friend inline bool operator>(const base_uint& a, const base_uint& b) { return a.CompareTo(b) > 0; } friend inline bool operator>(const base_uint& a, const base_uint& b) { return a.CompareTo(b) > 0; }

View file

@ -5,7 +5,7 @@
#include <bench/bench.h> #include <bench/bench.h>
#include <blockfilter.h> #include <blockfilter.h>
static const GCSFilter::ElementSet GenerateGCSTestElements() static GCSFilter::ElementSet GenerateGCSTestElements()
{ {
GCSFilter::ElementSet elements; GCSFilter::ElementSet elements;

View file

@ -24,7 +24,7 @@ using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WalletContext; using wallet::WalletContext;
using wallet::WalletDatabase; using wallet::WalletDatabase;
static const std::shared_ptr<CWallet> BenchLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, DatabaseOptions& options) static std::shared_ptr<CWallet> BenchLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, DatabaseOptions& options)
{ {
bilingual_str error; bilingual_str error;
std::vector<bilingual_str> warnings; std::vector<bilingual_str> warnings;

View file

@ -16,7 +16,7 @@
ExternalSigner::ExternalSigner(const std::string& command, const std::string chain, const std::string& fingerprint, const std::string name): m_command(command), m_chain(chain), m_fingerprint(fingerprint), m_name(name) {} ExternalSigner::ExternalSigner(const std::string& command, const std::string chain, const std::string& fingerprint, const std::string name): m_command(command), m_chain(chain), m_fingerprint(fingerprint), m_name(name) {}
const std::string ExternalSigner::NetworkArg() const std::string ExternalSigner::NetworkArg() const
{ {
return " --chain " + m_chain; return " --chain " + m_chain;
} }

View file

@ -24,7 +24,7 @@ private:
//! Bitcoin mainnet, testnet, etc //! Bitcoin mainnet, testnet, etc
std::string m_chain; std::string m_chain;
const std::string NetworkArg() const; std::string NetworkArg() const;
public: public:
//! @param[in] command the command which handles interaction with the external signer //! @param[in] command the command which handles interaction with the external signer

View file

@ -31,7 +31,7 @@
const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1"; const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
static const QString GetDefaultProxyAddress(); static QString GetDefaultProxyAddress();
/** Map GUI option ID to node setting name. */ /** Map GUI option ID to node setting name. */
static const char* SettingName(OptionsModel::OptionID option) static const char* SettingName(OptionsModel::OptionID option)
@ -308,7 +308,7 @@ static std::string ProxyString(bool is_set, QString ip, QString port)
return is_set ? QString(ip + ":" + port).toStdString() : ""; return is_set ? QString(ip + ":" + port).toStdString() : "";
} }
static const QString GetDefaultProxyAddress() static QString GetDefaultProxyAddress()
{ {
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT); return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
} }

View file

@ -1833,17 +1833,17 @@ DescriptorCache DescriptorCache::MergeAndDiff(const DescriptorCache& other)
return diff; return diff;
} }
const ExtPubKeyMap DescriptorCache::GetCachedParentExtPubKeys() const ExtPubKeyMap DescriptorCache::GetCachedParentExtPubKeys() const
{ {
return m_parent_xpubs; return m_parent_xpubs;
} }
const std::unordered_map<uint32_t, ExtPubKeyMap> DescriptorCache::GetCachedDerivedExtPubKeys() const std::unordered_map<uint32_t, ExtPubKeyMap> DescriptorCache::GetCachedDerivedExtPubKeys() const
{ {
return m_derived_xpubs; return m_derived_xpubs;
} }
const ExtPubKeyMap DescriptorCache::GetCachedLastHardenedExtPubKeys() const ExtPubKeyMap DescriptorCache::GetCachedLastHardenedExtPubKeys() const
{ {
return m_last_hardened_xpubs; return m_last_hardened_xpubs;
} }

View file

@ -66,11 +66,11 @@ public:
bool GetCachedLastHardenedExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const; bool GetCachedLastHardenedExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const;
/** Retrieve all cached parent xpubs */ /** Retrieve all cached parent xpubs */
const ExtPubKeyMap GetCachedParentExtPubKeys() const; ExtPubKeyMap GetCachedParentExtPubKeys() const;
/** Retrieve all cached derived xpubs */ /** Retrieve all cached derived xpubs */
const std::unordered_map<uint32_t, ExtPubKeyMap> GetCachedDerivedExtPubKeys() const; std::unordered_map<uint32_t, ExtPubKeyMap> GetCachedDerivedExtPubKeys() const;
/** Retrieve all cached last hardened xpubs */ /** Retrieve all cached last hardened xpubs */
const ExtPubKeyMap GetCachedLastHardenedExtPubKeys() const; ExtPubKeyMap GetCachedLastHardenedExtPubKeys() const;
/** Combine another DescriptorCache into this one. /** Combine another DescriptorCache into this one.
* Returns a cache containing the items from the other cache unknown to current cache * Returns a cache containing the items from the other cache unknown to current cache

View file

@ -104,7 +104,7 @@ struct ScriptParserContext {
return key.data; return key.data;
} }
const std::vector<unsigned char> ToPKHBytes(const Key& key) const std::vector<unsigned char> ToPKHBytes(const Key& key) const
{ {
if (key.is_hash) return key.data; if (key.is_hash) return key.data;
const auto h = Hash160(key.data); const auto h = Hash160(key.data);

View file

@ -47,7 +47,7 @@ size_t CallOneOf(FuzzedDataProvider& fuzzed_data_provider, Callables... callable
template <typename Collection> template <typename Collection>
auto& PickValue(FuzzedDataProvider& fuzzed_data_provider, Collection& col) auto& PickValue(FuzzedDataProvider& fuzzed_data_provider, Collection& col)
{ {
const auto sz = col.size(); auto sz{col.size()};
assert(sz >= 1); assert(sz >= 1);
auto it = col.begin(); auto it = col.begin();
std::advance(it, fuzzed_data_provider.ConsumeIntegralInRange<decltype(sz)>(0, sz - 1)); std::advance(it, fuzzed_data_provider.ConsumeIntegralInRange<decltype(sz)>(0, sz - 1));

View file

@ -13,7 +13,7 @@
/* Define a virtual block time, one block per 10 minutes after Nov 14 2014, 0:55:36am */ /* Define a virtual block time, one block per 10 minutes after Nov 14 2014, 0:55:36am */
static int32_t TestTime(int nHeight) { return 1415926536 + 600 * nHeight; } static int32_t TestTime(int nHeight) { return 1415926536 + 600 * nHeight; }
static const std::string StateName(ThresholdState state) static std::string StateName(ThresholdState state)
{ {
switch (state) { switch (state) {
case ThresholdState::DEFINED: return "DEFINED"; case ThresholdState::DEFINED: return "DEFINED";

View file

@ -1128,7 +1128,7 @@ void CTxMemPool::SetLoadTried(bool load_tried)
} }
const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept
{ {
switch (r) { switch (r) {
case MemPoolRemovalReason::EXPIRY: return "expiry"; case MemPoolRemovalReason::EXPIRY: return "expiry";

View file

@ -237,7 +237,7 @@ enum class MemPoolRemovalReason {
REPLACED, //!< Removed for replacement REPLACED, //!< Removed for replacement
}; };
const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept; std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
/** /**
* CTxMemPool stores valid-according-to-the-current-best-chain transactions * CTxMemPool stores valid-according-to-the-current-best-chain transactions

View file

@ -49,7 +49,7 @@ std::string FeeModes(const std::string& delimiter)
return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; }); return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
} }
const std::string InvalidEstimateModeErrorMessage() std::string InvalidEstimateModeErrorMessage()
{ {
return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\""; return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
} }

View file

@ -13,6 +13,6 @@ enum class FeeReason;
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode); bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
std::string StringForFeeReason(FeeReason reason); std::string StringForFeeReason(FeeReason reason);
std::string FeeModes(const std::string& delimiter); std::string FeeModes(const std::string& delimiter);
const std::string InvalidEstimateModeErrorMessage(); std::string InvalidEstimateModeErrorMessage();
#endif // BITCOIN_UTIL_FEES_H #endif // BITCOIN_UTIL_FEES_H

View file

@ -242,7 +242,7 @@ static std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, con
ArgsManager::ArgsManager() = default; ArgsManager::ArgsManager() = default;
ArgsManager::~ArgsManager() = default; ArgsManager::~ArgsManager() = default;
const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
{ {
std::set<std::string> unsuitables; std::set<std::string> unsuitables;
@ -262,7 +262,7 @@ const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
return unsuitables; return unsuitables;
} }
const std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const
{ {
// Section names to be recognized in the config file. // Section names to be recognized in the config file.
static const std::set<std::string> available_sections{ static const std::set<std::string> available_sections{

View file

@ -250,12 +250,12 @@ protected:
* on the command line or in a network-specific section in the * on the command line or in a network-specific section in the
* config file. * config file.
*/ */
const std::set<std::string> GetUnsuitableSectionOnlyArgs() const; std::set<std::string> GetUnsuitableSectionOnlyArgs() const;
/** /**
* Log warnings for unrecognized section names in the config file. * Log warnings for unrecognized section names in the config file.
*/ */
const std::list<SectionInfo> GetUnrecognizedSections() const; std::list<SectionInfo> GetUnrecognizedSections() const;
struct Command { struct Command {
/** The command (if one has been registered with AddCommand), or empty */ /** The command (if one has been registered with AddCommand), or empty */

View file

@ -17,7 +17,7 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept; std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept;
/** /**
* MainSignalsImpl manages a list of shared_ptr<CValidationInterface> callbacks. * MainSignalsImpl manages a list of shared_ptr<CValidationInterface> callbacks.

View file

@ -397,7 +397,7 @@ static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nM
} }
static const std::vector<RPCResult> TransactionDescriptionString() static std::vector<RPCResult> TransactionDescriptionString()
{ {
return{{RPCResult::Type::NUM, "confirmations", "The number of confirmations for the transaction. Negative confirmations means the\n" return{{RPCResult::Type::NUM, "confirmations", "The number of confirmations for the transaction. Negative confirmations means the\n"
"transaction conflicted that many blocks ago."}, "transaction conflicted that many blocks ago."},

View file

@ -1664,7 +1664,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
return set_address; return set_address;
} }
const std::unordered_set<CScript, SaltedSipHasher> LegacyScriptPubKeyMan::GetScriptPubKeys() const std::unordered_set<CScript, SaltedSipHasher> LegacyScriptPubKeyMan::GetScriptPubKeys() const
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
std::unordered_set<CScript, SaltedSipHasher> spks; std::unordered_set<CScript, SaltedSipHasher> spks;
@ -2650,17 +2650,17 @@ void DescriptorScriptPubKeyMan::WriteDescriptor()
} }
} }
const WalletDescriptor DescriptorScriptPubKeyMan::GetWalletDescriptor() const WalletDescriptor DescriptorScriptPubKeyMan::GetWalletDescriptor() const
{ {
return m_wallet_descriptor; return m_wallet_descriptor;
} }
const std::unordered_set<CScript, SaltedSipHasher> DescriptorScriptPubKeyMan::GetScriptPubKeys() const std::unordered_set<CScript, SaltedSipHasher> DescriptorScriptPubKeyMan::GetScriptPubKeys() const
{ {
return GetScriptPubKeys(0); return GetScriptPubKeys(0);
} }
const std::unordered_set<CScript, SaltedSipHasher> DescriptorScriptPubKeyMan::GetScriptPubKeys(int32_t minimum_index) const std::unordered_set<CScript, SaltedSipHasher> DescriptorScriptPubKeyMan::GetScriptPubKeys(int32_t minimum_index) const
{ {
LOCK(cs_desc_man); LOCK(cs_desc_man);
std::unordered_set<CScript, SaltedSipHasher> script_pub_keys; std::unordered_set<CScript, SaltedSipHasher> script_pub_keys;

View file

@ -36,7 +36,7 @@ class WalletStorage
{ {
public: public:
virtual ~WalletStorage() = default; virtual ~WalletStorage() = default;
virtual const std::string GetDisplayName() const = 0; virtual std::string GetDisplayName() const = 0;
virtual WalletDatabase& GetDatabase() const = 0; virtual WalletDatabase& GetDatabase() const = 0;
virtual bool IsWalletFlagSet(uint64_t) const = 0; virtual bool IsWalletFlagSet(uint64_t) const = 0;
virtual void UnsetBlankWalletFlag(WalletBatch&) = 0; virtual void UnsetBlankWalletFlag(WalletBatch&) = 0;
@ -243,7 +243,7 @@ public:
virtual uint256 GetID() const { return uint256(); } virtual uint256 GetID() const { return uint256(); }
/** Returns a set of all the scriptPubKeys that this ScriptPubKeyMan watches */ /** Returns a set of all the scriptPubKeys that this ScriptPubKeyMan watches */
virtual const std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const { return {}; }; virtual std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const { return {}; };
/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */ /** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
template<typename... Params> template<typename... Params>
@ -512,7 +512,7 @@ public:
const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; } const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
std::set<CKeyID> GetKeys() const override; std::set<CKeyID> GetKeys() const override;
const std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override; std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override;
/** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyScriptPubKeyMan. /** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyScriptPubKeyMan.
* Does not modify this ScriptPubKeyMan. */ * Does not modify this ScriptPubKeyMan. */
@ -641,9 +641,9 @@ public:
void AddDescriptorKey(const CKey& key, const CPubKey &pubkey); void AddDescriptorKey(const CKey& key, const CPubKey &pubkey);
void WriteDescriptor(); void WriteDescriptor();
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
const std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override; std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override;
const std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys(int32_t minimum_index) const; std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys(int32_t minimum_index) const;
int32_t GetEndRange() const; int32_t GetEndRange() const;
bool GetDescriptorString(std::string& out, const bool priv) const; bool GetDescriptorString(std::string& out, const bool priv) const;

View file

@ -43,7 +43,7 @@ static_assert(WALLET_INCREMENTAL_RELAY_FEE >= DEFAULT_INCREMENTAL_RELAY_FEE, "wa
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
static const std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context) static std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
{ {
DatabaseOptions options; DatabaseOptions options;
options.create_flags = WALLET_FLAG_DESCRIPTORS; options.create_flags = WALLET_FLAG_DESCRIPTORS;

View file

@ -821,7 +821,8 @@ public:
bool IsLegacy() const; bool IsLegacy() const;
/** Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name */ /** Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name */
const std::string GetDisplayName() const override { std::string GetDisplayName() const override
{
std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName(); std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
return strprintf("[%s]", wallet_name); return strprintf("[%s]", wallet_name);
}; };

View file

@ -47,7 +47,7 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
wallet_instance->TopUpKeyPool(); wallet_instance->TopUpKeyPool();
} }
static const std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::path& path, const ArgsManager& args, DatabaseOptions options) static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::path& path, const ArgsManager& args, DatabaseOptions options)
{ {
DatabaseStatus status; DatabaseStatus status;
bilingual_str error; bilingual_str error;