refactor: Remove remaining std::bind, check via clang-tidy
What changed, and why it matters
This commit is a routine code cleanup: it replaces old-style std::bind calls with modern C++ lambda functions and adds a clang-tidy rule to prevent std::bind from being reintroduced. There is no security-relevant change here.
No security action required. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors four signal/slot and callback connection sites in Bitcoin Core to use lambda expressions instead of std::bind. It also enables the modernize-avoid-bind clang-tidy check. The functional behavior of each callback is preserved exactly, including parameter order and captured this pointers. No memory-management, concurrency, validation, or cryptographic logic is modified.
Changed components
src/qt/splashscreen.cppsrc/qt/transactiontablemodel.cppsrc/wallet/wallet.cppsrc/.clang-tidyInspect captured patch +16 / −5
diff --git a/src/.clang-tidy b/src/.clang-tidy
index f54e07fa..cd42491a 100644
--- a/src/.clang-tidy
+++ b/src/.clang-tidy
@@ -10,6 +10,7 @@ bugprone-unhandled-self-assignment,
bugprone-unused-return-value,
misc-unused-using-decls,
misc-no-recursion,
+modernize-avoid-bind,
modernize-deprecated-headers,
modernize-use-default-member-init,
modernize-use-emplace,
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index 237df5f6..553f6789 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -180,8 +180,12 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
void SplashScreen::subscribeToCoreSignals()
{
// Connect signals to client
- m_handler_init_message = m_node->handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
- m_handler_show_progress = m_node->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
+ m_handler_init_message = m_node->handleInitMessage([this](const std::string& message) {
+ InitMessage(this, message);
+ });
+ m_handler_show_progress = m_node->handleShowProgress([this](const std::string& title, int nProgress, bool resume_possible) {
+ ShowProgress(this, title, nProgress, resume_possible);
+ });
m_handler_init_wallet = m_node->handleInitWallet([this]() { handleLoadWallet(); });
}
@@ -190,7 +194,9 @@ void SplashScreen::handleLoadWallet()
#ifdef ENABLE_WALLET
if (!WalletModel::isWalletEnabled()) return;
m_handler_load_wallet = m_node->walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
- m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, false)));
+ m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress([this](const std::string& title, int nProgress) {
+ ShowProgress(this, title, nProgress, /*resume_possible=*/false);
+ }));
m_connected_wallets.emplace_back(std::move(wallet));
});
#endif
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index 28734e3e..6c09c4d7 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -712,7 +712,9 @@ void TransactionTablePriv::DispatchNotifications()
void TransactionTableModel::subscribeToCoreSignals()
{
// Connect signals to wallet
- m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(std::bind(&TransactionTablePriv::NotifyTransactionChanged, priv, std::placeholders::_1, std::placeholders::_2));
+ m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged([this](const Txid& hash, ChangeType status) {
+ priv->NotifyTransactionChanged(hash, status);
+ });
m_handler_show_progress = walletModel->wallet().handleShowProgress([this](const std::string&, int progress) {
priv->m_loading = progress < 100;
priv->DispatchNotifications();
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index de260f8e..d12d3877 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3543,7 +3543,9 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
{
for (const auto& spk_man : GetActiveScriptPubKeyMans()) {
spk_man->NotifyCanGetAddressesChanged.connect(NotifyCanGetAddressesChanged);
- spk_man->NotifyFirstKeyTimeChanged.connect(std::bind(&CWallet::MaybeUpdateBirthTime, this, std::placeholders::_2));
+ spk_man->NotifyFirstKeyTimeChanged.connect([this](const ScriptPubKeyMan*, int64_t time) {
+ MaybeUpdateBirthTime(time);
+ });
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.