Skip to content

Commit 78407b9

Browse files
dergoeggestickies-vglozow
committed
[clang-tidy] Enable the misc-no-recursion check
Co-authored-by: stickies-v <[email protected]> Co-authored-by: Gloria Zhao <[email protected]>
1 parent f0794cb commit 78407b9

17 files changed

+39
-0
lines changed

doc/developer-notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ code.
115115
Use `reinterpret_cast` and `const_cast` as appropriate.
116116
- Prefer [`list initialization ({})`](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-list) where possible.
117117
For example `int x{0};` instead of `int x = 0;` or `int x(0);`
118+
- Recursion is checked by clang-tidy and thus must be made explicit. Use
119+
`NOLINTNEXTLINE(misc-no-recursion)` to suppress the check.
118120

119121
For function calls a namespace should be specified explicitly, unless such functions have been declared within it.
120122
Otherwise, [argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl), also known as ADL, could be

src/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ bugprone-string-constructor,
66
bugprone-use-after-move,
77
bugprone-lambda-function-name,
88
misc-unused-using-decls,
9+
misc-no-recursion,
910
modernize-use-default-member-init,
1011
modernize-use-emplace,
1112
modernize-use-noexcept,

src/merkleblock.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std:
5454
txn = CPartialMerkleTree(vHashes, vMatch);
5555
}
5656

57+
// NOLINTNEXTLINE(misc-no-recursion)
5758
uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, const std::vector<uint256> &vTxid) {
5859
//we can never have zero txs in a merkle block, we always need the coinbase tx
5960
//if we do not have this assert, we can hit a memory access violation when indexing into vTxid
@@ -74,6 +75,7 @@ uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, const std::ve
7475
}
7576
}
7677

78+
// NOLINTNEXTLINE(misc-no-recursion)
7779
void CPartialMerkleTree::TraverseAndBuild(int height, unsigned int pos, const std::vector<uint256> &vTxid, const std::vector<bool> &vMatch) {
7880
// determine whether this node is the parent of at least one matched txid
7981
bool fParentOfMatch = false;
@@ -92,6 +94,7 @@ void CPartialMerkleTree::TraverseAndBuild(int height, unsigned int pos, const st
9294
}
9395
}
9496

97+
// NOLINTNEXTLINE(misc-no-recursion)
9598
uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, unsigned int &nBitsUsed, unsigned int &nHashUsed, std::vector<uint256> &vMatch, std::vector<unsigned int> &vnIndex) {
9699
if (nBitsUsed >= vBits.size()) {
97100
// overflowed the bits array - failure

src/node/interfaces.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ class NodeImpl : public Node
406406
NodeContext* m_context{nullptr};
407407
};
408408

409+
// NOLINTNEXTLINE(misc-no-recursion)
409410
bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active, const BlockManager& blockman)
410411
{
411412
if (!index) return false;

src/qt/optionsmodel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
396396
return successful;
397397
}
398398

399+
// NOLINTNEXTLINE(misc-no-recursion)
399400
QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) const
400401
{
401402
auto setting = [&]{ return node().getPersistentSetting(SettingName(option) + suffix); };
@@ -508,6 +509,7 @@ QFont OptionsModel::getFontForMoney() const
508509
return getFontForChoice(m_font_money);
509510
}
510511

512+
// NOLINTNEXTLINE(misc-no-recursion)
511513
bool OptionsModel::setOption(OptionID option, const QVariant& value, const std::string& suffix)
512514
{
513515
auto changed = [&] { return value.isValid() && value != getOption(option, suffix); };

src/rpc/util.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ struct Sections {
414414
/**
415415
* Recursive helper to translate an RPCArg into sections
416416
*/
417+
// NOLINTNEXTLINE(misc-no-recursion)
417418
void Push(const RPCArg& arg, const size_t current_indent = 5, const OuterType outer_type = OuterType::NONE)
418419
{
419420
const auto indent = std::string(current_indent, ' ');
@@ -953,6 +954,7 @@ std::string RPCArg::ToDescriptionString(bool is_named_arg) const
953954
return ret;
954955
}
955956

957+
// NOLINTNEXTLINE(misc-no-recursion)
956958
void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const int current_indent) const
957959
{
958960
// Indentation
@@ -1086,6 +1088,7 @@ static std::optional<UniValue::VType> ExpectedType(RPCResult::Type type)
10861088
NONFATAL_UNREACHABLE();
10871089
}
10881090

1091+
// NOLINTNEXTLINE(misc-no-recursion)
10891092
UniValue RPCResult::MatchesType(const UniValue& result) const
10901093
{
10911094
if (m_skip_type_check) {
@@ -1164,6 +1167,7 @@ void RPCResult::CheckInnerDoc() const
11641167
CHECK_NONFATAL(inner_needed != m_inner.empty());
11651168
}
11661169

1170+
// NOLINTNEXTLINE(misc-no-recursion)
11671171
std::string RPCArg::ToStringObj(const bool oneline) const
11681172
{
11691173
std::string res;
@@ -1202,6 +1206,7 @@ std::string RPCArg::ToStringObj(const bool oneline) const
12021206
NONFATAL_UNREACHABLE();
12031207
}
12041208

1209+
// NOLINTNEXTLINE(misc-no-recursion)
12051210
std::string RPCArg::ToString(const bool oneline) const
12061211
{
12071212
if (oneline && !m_opts.oneline_description.empty()) {
@@ -1228,6 +1233,7 @@ std::string RPCArg::ToString(const bool oneline) const
12281233
case Type::OBJ:
12291234
case Type::OBJ_NAMED_PARAMS:
12301235
case Type::OBJ_USER_KEYS: {
1236+
// NOLINTNEXTLINE(misc-no-recursion)
12311237
const std::string res = Join(m_inner, ",", [&](const RPCArg& i) { return i.ToStringObj(oneline); });
12321238
if (m_type == Type::OBJ) {
12331239
return "{" + res + "}";

src/rpc/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct RPCArgOptions {
162162
//!< methods set the also_positional flag and read values from both positions.
163163
};
164164

165+
// NOLINTNEXTLINE(misc-no-recursion)
165166
struct RPCArg {
166167
enum class Type {
167168
OBJ,
@@ -271,6 +272,7 @@ struct RPCArg {
271272
std::string ToDescriptionString(bool is_named_arg) const;
272273
};
273274

275+
// NOLINTNEXTLINE(misc-no-recursion)
274276
struct RPCResult {
275277
enum class Type {
276278
OBJ,

src/script/descriptor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ class DescriptorImpl : public Descriptor
599599
COMPAT, // string calculation that mustn't change over time to stay compatible with previous software versions
600600
};
601601

602+
// NOLINTNEXTLINE(misc-no-recursion)
602603
bool IsSolvable() const override
603604
{
604605
for (const auto& arg : m_subdescriptor_args) {
@@ -607,6 +608,7 @@ class DescriptorImpl : public Descriptor
607608
return true;
608609
}
609610

611+
// NOLINTNEXTLINE(misc-no-recursion)
610612
bool IsRange() const final
611613
{
612614
for (const auto& pubkey : m_pubkey_args) {
@@ -618,6 +620,7 @@ class DescriptorImpl : public Descriptor
618620
return false;
619621
}
620622

623+
// NOLINTNEXTLINE(misc-no-recursion)
621624
virtual bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, const StringType type, const DescriptorCache* cache = nullptr) const
622625
{
623626
size_t pos = 0;
@@ -630,6 +633,7 @@ class DescriptorImpl : public Descriptor
630633
return true;
631634
}
632635

636+
// NOLINTNEXTLINE(misc-no-recursion)
633637
virtual bool ToStringHelper(const SigningProvider* arg, std::string& out, const StringType type, const DescriptorCache* cache = nullptr) const
634638
{
635639
std::string extra = ToStringExtra();
@@ -682,6 +686,7 @@ class DescriptorImpl : public Descriptor
682686
return ret;
683687
}
684688

689+
// NOLINTNEXTLINE(misc-no-recursion)
685690
bool ExpandHelper(int pos, const SigningProvider& arg, const DescriptorCache* read_cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out, DescriptorCache* write_cache) const
686691
{
687692
std::vector<std::pair<CPubKey, KeyOriginInfo>> entries;
@@ -723,6 +728,7 @@ class DescriptorImpl : public Descriptor
723728
return ExpandHelper(pos, DUMMY_SIGNING_PROVIDER, &read_cache, output_scripts, out, nullptr);
724729
}
725730

731+
// NOLINTNEXTLINE(misc-no-recursion)
726732
void ExpandPrivate(int pos, const SigningProvider& provider, FlatSigningProvider& out) const final
727733
{
728734
for (const auto& p : m_pubkey_args) {
@@ -750,6 +756,7 @@ class DescriptorImpl : public Descriptor
750756

751757
std::optional<int64_t> MaxSatisfactionElems() const override { return {}; }
752758

759+
// NOLINTNEXTLINE(misc-no-recursion)
753760
void GetPubKeys(std::set<CPubKey>& pubkeys, std::set<CExtPubKey>& ext_pubs) const override
754761
{
755762
for (const auto& p : m_pubkey_args) {
@@ -1579,6 +1586,7 @@ struct KeyParser {
15791586
};
15801587

15811588
/** Parse a script in a particular context. */
1589+
// NOLINTNEXTLINE(misc-no-recursion)
15821590
std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const char>& sp, ParseScriptContext ctx, FlatSigningProvider& out, std::string& error)
15831591
{
15841592
using namespace spanparsing;
@@ -1886,6 +1894,7 @@ std::unique_ptr<DescriptorImpl> InferMultiA(const CScript& script, ParseScriptCo
18861894
return std::make_unique<MultiADescriptor>(match->first, std::move(keys));
18871895
}
18881896

1897+
// NOLINTNEXTLINE(misc-no-recursion)
18891898
std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptContext ctx, const SigningProvider& provider)
18901899
{
18911900
if (ctx == ParseScriptContext::P2TR && script.size() == 34 && script[0] == 32 && script[33] == OP_CHECKSIG) {

src/test/miniscript_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ using miniscript::operator"" _mst;
297297
using Node = miniscript::Node<CPubKey>;
298298

299299
/** Compute all challenges (pubkeys, hashes, timelocks) that occur in a given Miniscript. */
300+
// NOLINTNEXTLINE(misc-no-recursion)
300301
std::set<Challenge> FindChallenges(const NodeRef& ref) {
301302
std::set<Challenge> chal;
302303
for (const auto& key : ref->keys) {

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ std::shared_ptr<const CBlock> MinerTestingSetup::BadBlock(const uint256& prev_ha
127127
return ret;
128128
}
129129

130+
// NOLINTNEXTLINE(misc-no-recursion)
130131
void MinerTestingSetup::BuildChain(const uint256& root, int height, const unsigned int invalid_rate, const unsigned int branch_rate, const unsigned int max_size, std::vector<std::shared_ptr<const CBlock>>& blocks)
131132
{
132133
if (height <= 0 || blocks.size() >= max_size) return;

0 commit comments

Comments
 (0)