clang-tidy: Enable modernize-avoid-bind check
The check finds uses of std::bind and boost::bind and replaces them
with lambdas.
Lambdas will use value-capture unless reference capture is explicitly
requested with std::ref or boost::ref.
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I4491650a46eaab1588474b26efc622e89232ef02
diff --git a/.clang-tidy b/.clang-tidy
index 873d901..4642279 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -204,6 +204,7 @@
misc-unconventional-assign-operator,
misc-uniqueptr-reset-release,
misc-unused-using-decls,
+modernize-avoid-bind,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
diff --git a/fault-monitor/fru-fault-monitor.hpp b/fault-monitor/fru-fault-monitor.hpp
index e5ddc53..fc6cafa 100644
--- a/fault-monitor/fru-fault-monitor.hpp
+++ b/fault-monitor/fru-fault-monitor.hpp
@@ -47,8 +47,7 @@
Remove(sdbusplus::bus_t& bus, const std::string& path) :
inventoryPath(path),
matchRemoved(bus, match(path),
- std::bind(std::mem_fn(&Remove::removed), this,
- std::placeholders::_1))
+ [this](sdbusplus::message_t& m) { removed(m); })
{
// Do nothing
}
@@ -99,12 +98,11 @@
* @param[in] bus - The Dbus bus object
*/
explicit Add(sdbusplus::bus_t& bus) :
- matchCreated(
- bus,
- sdbusplus::bus::match::rules::interfacesAdded() +
- sdbusplus::bus::match::rules::path_namespace(
- "/xyz/openbmc_project/logging"),
- std::bind(std::mem_fn(&Add::created), this, std::placeholders::_1))
+ matchCreated(bus,
+ sdbusplus::bus::match::rules::interfacesAdded() +
+ sdbusplus::bus::match::rules::path_namespace(
+ "/xyz/openbmc_project/logging"),
+ [this](sdbusplus::message_t& m) { created(m); })
{
processExistingCallouts(bus);
}
diff --git a/fault-monitor/operational-status-monitor.hpp b/fault-monitor/operational-status-monitor.hpp
index 3b67edb..6bd2efc 100644
--- a/fault-monitor/operational-status-monitor.hpp
+++ b/fault-monitor/operational-status-monitor.hpp
@@ -47,8 +47,7 @@
"sender='xyz.openbmc_project.Inventory.Manager', "
"arg0namespace='xyz.openbmc_project.State.Decorator."
"OperationalStatus'",
- std::bind(std::mem_fn(&Monitor::matchHandler), this,
- std::placeholders::_1))
+ [this](sdbusplus::message_t& m) { matchHandler(m); })
{}
diff --git a/manager/json-config.hpp b/manager/json-config.hpp
index 64441b3..d02af56 100644
--- a/manager/json-config.hpp
+++ b/manager/json-config.hpp
@@ -41,8 +41,7 @@
sdbusplus::bus::match::rules::interfacesAdded() +
sdbusplus::bus::match::rules::sender(
"xyz.openbmc_project.EntityManager"),
- std::bind(&JsonConfig::ifacesAddedCallback, this,
- std::placeholders::_1));
+ [this](sdbusplus::message_t& m) { ifacesAddedCallback(m); });
getFilePath();
if (!confFile.empty())
diff --git a/manager/lamptest/lamptest.hpp b/manager/lamptest/lamptest.hpp
index 1d9dd86..c7804c8 100644
--- a/manager/lamptest/lamptest.hpp
+++ b/manager/lamptest/lamptest.hpp
@@ -38,8 +38,8 @@
* @param[in] manager - reference to manager instance
*/
LampTest(const sdeventplus::Event& event, Manager& manager) :
- timer(event, std::bind(std::mem_fn(&LampTest::timeOutHandler), this)),
- manager(manager), groupObj(NULL)
+ timer(event, [this](auto&) { timeOutHandler(); }), manager(manager),
+ groupObj(NULL)
{
// Get the force update and/or skipped physical LEDs names from the
// lamp-test-led-overrides.json file during lamp
diff --git a/manager/led-main.cpp b/manager/led-main.cpp
index 450f4d7..7791747 100644
--- a/manager/led-main.cpp
+++ b/manager/led-main.cpp
@@ -70,14 +70,17 @@
groups.emplace_back(std::make_unique<phosphor::led::Group>(
bus, LAMP_TEST_OBJECT, manager, serializePtr,
- std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler),
- &lampTest, std::placeholders::_1, std::placeholders::_2)));
+ [&lampTest](auto&& arg1, auto&& arg2) {
+ return lampTest.requestHandler(std::forward<decltype(arg1)>(arg1),
+ std::forward<decltype(arg2)>(arg2));
+ }));
// Register a lamp test method in the manager class, and call this method
// when the lamp test is started
- manager.setLampTestCallBack(
- std::bind(std::mem_fn(&phosphor::led::LampTest::processLEDUpdates),
- &lampTest, std::placeholders::_1, std::placeholders::_2));
+ manager.setLampTestCallBack([&lampTest](auto&& arg1, auto&& arg2) {
+ return lampTest.processLEDUpdates(std::forward<decltype(arg1)>(arg1),
+ std::forward<decltype(arg2)>(arg2));
+ });
#endif
/** Now create so many dbus objects as there are groups */