Skip to content

Commit 0da559e

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24661: refactor: Use clang-tidy syntax for C++ named arguments
37a16ff refactor: fix clang-tidy named args usage (fanquake) Pull request description: > Incorrect named args are source of bugs, like bitcoin/bitcoin#22979. > To allow them being checked by clang-tidy, use a format it can understand. Picks up #23545, with some additional changes and some feedback addressed. With these changes invoking `./autogen.sh && ./configure CC=clang-12 CXX=clang++-12 && make clean && bear make -j9 && ( cd ./src/ && run-clang-tidy-12 -j9 )` no-longer results in named argument errors out of `clang-tidy`. Ultimately I think we should just add `clang-tidy-*` jobs to the CI and automate things away. ACKs for top commit: MarcoFalke: cr ACK 37a16ff Tree-SHA512: 9bfc0d006eb187755b4fdb0bd92cee9266fc0816be42065ef7dcd885b9020ff12e3cdd7ca3a831613a56a0206d448e690ee4e1fa37628fa2013860e17f416ff3
2 parents 62efdfb + 37a16ff commit 0da559e

32 files changed

+61
-61
lines changed

src/addrdb.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void ReadFromStream(AddrMan& addr, CDataStream& ssPeers)
185185
std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const ArgsManager& args, std::unique_ptr<AddrMan>& addrman)
186186
{
187187
auto check_addrman = std::clamp<int32_t>(args.GetIntArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
188-
addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
188+
addrman = std::make_unique<AddrMan>(asmap, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
189189

190190
int64_t nStart = GetTimeMillis();
191191
const auto path_addr{args.GetDataDirNet() / "peers.dat"};
@@ -194,7 +194,7 @@ std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const A
194194
LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman->size(), GetTimeMillis() - nStart);
195195
} catch (const DbNotFoundError&) {
196196
// Addrman can be in an inconsistent state after failure, reset it
197-
addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
197+
addrman = std::make_unique<AddrMan>(asmap, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
198198
LogPrintf("Creating peers.dat because the file was not found (%s)\n", fs::quoted(fs::PathToString(path_addr)));
199199
DumpPeerAddresses(args, *addrman);
200200
} catch (const InvalidAddrManVersionError&) {
@@ -203,7 +203,7 @@ std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const A
203203
return strprintf(_("Failed to rename invalid peers.dat file. Please move or delete it and try again."));
204204
}
205205
// Addrman can be in an inconsistent state after failure, reset it
206-
addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
206+
addrman = std::make_unique<AddrMan>(asmap, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
207207
LogPrintf("Creating new peers.dat because the file version was not compatible (%s). Original backed up to peers.dat.bak\n", fs::quoted(fs::PathToString(path_addr)));
208208
DumpPeerAddresses(args, *addrman);
209209
} catch (const std::exception& e) {

src/bench/addrman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void AddrManGetAddr(benchmark::Bench& bench)
101101
FillAddrMan(addrman);
102102

103103
bench.run([&] {
104-
const auto& addresses = addrman.GetAddr(/* max_addresses */ 2500, /* max_pct */ 23, /* network */ std::nullopt);
104+
const auto& addresses = addrman.GetAddr(/*max_addresses=*/2500, /*max_pct=*/23, /*network=*/std::nullopt);
105105
assert(addresses.size() > 0);
106106
});
107107
}

src/bench/mempool_stress.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
8686
if (bench.complexityN() > 1) {
8787
childTxs = static_cast<int>(bench.complexityN());
8888
}
89-
std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /* min_ancestors */ 1);
89+
std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /*min_ancestors=*/1);
9090
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN);
9191
CTxMemPool pool;
9292
LOCK2(cs_main, pool.cs);
@@ -103,15 +103,15 @@ static void MempoolCheck(benchmark::Bench& bench)
103103
{
104104
FastRandomContext det_rand{true};
105105
const int childTxs = bench.complexityN() > 1 ? static_cast<int>(bench.complexityN()) : 2000;
106-
const std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /* min_ancestors */ 5);
106+
const std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /*min_ancestors=*/5);
107107
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN, {"-checkmempool=1"});
108108
CTxMemPool pool;
109109
LOCK2(cs_main, pool.cs);
110110
const CCoinsViewCache& coins_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().CoinsTip();
111111
for (auto& tx : ordered_coins) AddTx(tx, pool);
112112

113113
bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {
114-
pool.check(coins_tip, /* spendheight */ 2);
114+
pool.check(coins_tip, /*spendheight=*/2);
115115
});
116116
}
117117

src/bench/rpc_mempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ static void RpcMempool(benchmark::Bench& bench)
2929
tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
3030
tx.vout[0].nValue = i;
3131
const CTransactionRef tx_r{MakeTransactionRef(tx)};
32-
AddTx(tx_r, /* fee */ i, pool);
32+
AddTx(tx_r, /*fee=*/i, pool);
3333
}
3434

3535
bench.run([&] {
36-
(void)MempoolToJSON(pool, /*verbose*/ true);
36+
(void)MempoolToJSON(pool, /*verbose=*/true);
3737
});
3838
}
3939

src/bench/wallet_balance.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
5252
});
5353
}
5454

55-
static void WalletBalanceDirty(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ true, /* add_mine */ true); }
56-
static void WalletBalanceClean(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_mine */ true); }
57-
static void WalletBalanceMine(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_mine */ true); }
58-
static void WalletBalanceWatch(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_mine */ false); }
55+
static void WalletBalanceDirty(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/true, /*add_mine=*/true); }
56+
static void WalletBalanceClean(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/false, /*add_mine=*/true); }
57+
static void WalletBalanceMine(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/false, /*add_mine=*/true); }
58+
static void WalletBalanceWatch(benchmark::Bench& bench) { WalletBalance(bench, /*set_dirty=*/false, /*add_mine=*/false); }
5959

6060
BENCHMARK(WalletBalanceDirty);
6161
BENCHMARK(WalletBalanceClean);

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int main(int argc, char* argv[])
192192
bool new_block;
193193
auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
194194
RegisterSharedValidationInterface(sc);
195-
bool accepted = chainman.ProcessNewBlock(chainparams, blockptr, /* force_processing */ true, /* new_block */ &new_block);
195+
bool accepted = chainman.ProcessNewBlock(chainparams, blockptr, /*force_processing=*/true, /*new_block=*/&new_block);
196196
UnregisterSharedValidationInterface(sc);
197197
if (!new_block && accepted) {
198198
std::cerr << "duplicate" << std::endl;

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,7 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
27822782
auto r = m_addr_response_caches.emplace(cache_id, CachedAddrResponse{});
27832783
CachedAddrResponse& cache_entry = r.first->second;
27842784
if (cache_entry.m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
2785-
cache_entry.m_addrs_response_cache = GetAddresses(max_addresses, max_pct, /* network */ std::nullopt);
2785+
cache_entry.m_addrs_response_cache = GetAddresses(max_addresses, max_pct, /*network=*/std::nullopt);
27862786
// Choosing a proper cache lifetime is a trade-off between the privacy leak minimization
27872787
// and the usefulness of ADDR responses to honest users.
27882788
//

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,7 +3562,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
35623562
BlockValidationState state;
35633563
if (!m_chainman.ProcessNewBlockHeaders({cmpctblock.header}, state, m_chainparams, &pindex)) {
35643564
if (state.IsInvalid()) {
3565-
MaybePunishNodeForBlock(pfrom.GetId(), state, /*via_compact_block*/ true, "invalid header via cmpctblock");
3565+
MaybePunishNodeForBlock(pfrom.GetId(), state, /*via_compact_block=*/true, "invalid header via cmpctblock");
35663566
return;
35673567
}
35683568
}
@@ -3902,7 +3902,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
39023902
peer->m_addrs_to_send.clear();
39033903
std::vector<CAddress> vAddr;
39043904
if (pfrom.HasPermission(NetPermissionFlags::Addr)) {
3905-
vAddr = m_connman.GetAddresses(MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND, /* network */ std::nullopt);
3905+
vAddr = m_connman.GetAddresses(MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND, /*network=*/std::nullopt);
39063906
} else {
39073907
vAddr = m_connman.GetAddresses(pfrom, MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND);
39083908
}

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class ChainImpl : public Chain
590590
bool relay,
591591
std::string& err_string) override
592592
{
593-
const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback*/ false);
593+
const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback=*/false);
594594
// Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures.
595595
// Note: this will need to be updated if BroadcastTransactions() is updated to return other non-mempool failures
596596
// that Chain clients do not need to know about.

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ void BitcoinGUI::aboutClicked()
853853
if(!clientModel)
854854
return;
855855

856-
auto dlg = new HelpMessageDialog(this, /* about */ true);
856+
auto dlg = new HelpMessageDialog(this, /*about=*/true);
857857
GUIUtil::ShowModalDialogAsynchronously(dlg);
858858
}
859859

0 commit comments

Comments
 (0)