std::bind has many issues:
- It is verbosely listing all placeholders, but in a meaningless way, because it doesn’t name the args or their types.
- It silently ignores args passed to it, when one arg is overridden. For example [1] compiles fine on current master.
- Accidentally duplicated placeholders compile fine as well.
- Usually the placeholders aren’t even needed.
- This makes it hard to review, understand, and maintain.
Fix all issues by using std::bind_front from C++20, which allows to drop the brittle _1, _2, ... placeholders. The replacement should be correct, if the trailing placeholders are ordered.
Introducing the same silent bug on top of this pull request [2] will now lead to a compile failure.
[1]
0diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
1index 694fb535b5..7661dd361e 100644
2--- a/src/qt/walletmodel.cpp
3+++ b/src/qt/walletmodel.cpp
4@@ -412,3 +412,3 @@ void WalletModel::subscribeToCoreSignals()
5 m_handler_status_changed = m_wallet->handleStatusChanged(std::bind(&NotifyKeyStoreStatusChanged, this));
6- m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind(NotifyAddressBookChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
7+ m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind(NotifyAddressBookChanged, this, CTxDestination{}, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
8 m_handler_transaction_changed = m_wallet->handleTransactionChanged(std::bind(NotifyTransactionChanged, this, std::placeholders::_1, std::placeholders::_2));
[2]
0diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
1index 578713c0ab..84cced741c 100644
2--- a/src/qt/walletmodel.cpp
3+++ b/src/qt/walletmodel.cpp
4@@ -412,3 +412,3 @@ void WalletModel::subscribeToCoreSignals()
5 m_handler_status_changed = m_wallet->handleStatusChanged(std::bind_front(&NotifyKeyStoreStatusChanged, this));
6- m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind_front(NotifyAddressBookChanged, this));
7+ m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind_front(NotifyAddressBookChanged, this, CTxDestination{}));
8 m_handler_transaction_changed = m_wallet->handleTransactionChanged(std::bind_front(NotifyTransactionChanged, this));