Enable clang-tidy forward reference checks
Clang-13 adds new checks we can turn on, which find quite a few errors.
Tested: Code compiles
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I74b780760014c898cc440b37aea640b33e91c439
diff --git a/.clang-tidy b/.clang-tidy
index 0122e24..db950cb 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -21,6 +21,7 @@
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
+bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-narrowing-conversions,
bugprone-no-escape,
diff --git a/http/app.hpp b/http/app.hpp
index 4735197..b4ccd95 100644
--- a/http/app.hpp
+++ b/http/app.hpp
@@ -47,7 +47,7 @@
template <typename Adaptor>
void handleUpgrade(const Request& req, Response& res, Adaptor&& adaptor)
{
- router.handleUpgrade(req, res, std::move(adaptor));
+ router.handleUpgrade(req, res, std::forward<Adaptor>(adaptor));
}
void handle(Request& req,
diff --git a/http/routing.hpp b/http/routing.hpp
index fe9c7e9..c8946e4 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -208,7 +208,7 @@
const Request&>::value,
int>::type = 0)
{
- handler = [f = std::move(f)](
+ handler = [f = std::forward<Func>(f)](
const Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Args... args) { asyncResp->res.result(f(args...)); };
@@ -565,7 +565,7 @@
"types: "
"string, int, crow::response, nlohmann::json");
- handler = [f = std::move(f)](
+ handler = [f = std::forward<Func>(f)](
const Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Args... args) { asyncResp->res.result(f(args...)); };
@@ -591,7 +591,7 @@
"types: "
"string, int, crow::response,nlohmann::json");
- handler = [f = std::move(f)](
+ handler = [f = std::forward<Func>(f)](
const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Args... args) { asyncResp->res.result(f(req, args...)); };
@@ -624,7 +624,7 @@
"return "
"type");
- handler = std::move(f);
+ handler = std::forward<Func>(f);
}
template <typename Func>
@@ -1201,7 +1201,8 @@
// any uncaught exceptions become 500s
try
{
- rules[ruleIndex]->handleUpgrade(req, res, std::move(adaptor));
+ rules[ruleIndex]->handleUpgrade(req, res,
+ std::forward<Adaptor>(adaptor));
}
catch (const std::exception& e)
{
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index 306a499..105616d 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -27,7 +27,7 @@
BMCWEB_LOG_DEBUG << "Trying to resolve: " << host << ":" << port;
uint64_t flag = 0;
crow::connections::systemBus->async_method_call(
- [host, port, handler{std::move(handler)}](
+ [host, port, handler{std::forward<ResolveHandler>(handler)}](
const boost::system::error_code ec,
const std::vector<
std::tuple<int32_t, int32_t, std::vector<uint8_t>>>& resp,
diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index 4853231..872ca61 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -111,8 +111,9 @@
std::vector<std::pair<std::string, std::vector<std::string>>>;
crow::connections::systemBus->async_method_call(
- [callback{std::move(callback)}](const boost::system::error_code ec,
- const GetObjectType& objectNames) {
+ [callback{std::forward<Callback>(callback)}](
+ const boost::system::error_code ec,
+ const GetObjectType& objectNames) {
callback(!ec && objectNames.size() != 0);
},
"xyz.openbmc_project.ObjectMapper",
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 049f9a6..8735178 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -931,7 +931,8 @@
CallbackFunc&& callback)
{
crow::connections::systemBus->async_method_call(
- [ethifaceId{std::string{ethifaceId}}, callback{std::move(callback)}](
+ [ethifaceId{std::string{ethifaceId}},
+ callback{std::forward<CallbackFunc>(callback)}](
const boost::system::error_code errorCode,
dbus::utility::ManagedObjectType& resp) {
EthernetInterfaceData ethData{};
@@ -982,7 +983,7 @@
void getEthernetIfaceList(CallbackFunc&& callback)
{
crow::connections::systemBus->async_method_call(
- [callback{std::move(callback)}](
+ [callback{std::forward<CallbackFunc>(callback)}](
const boost::system::error_code errorCode,
dbus::utility::ManagedObjectType& resp) {
// Callback requires vector<string> to retrieve all available
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 8faae3f..db9b5aa 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -317,7 +317,8 @@
CallbackFunc&& callback)
{
crow::connections::systemBus->async_method_call(
- [ethIfaceId{std::string{ethIfaceId}}, callback{std::move(callback)}](
+ [ethIfaceId{std::string{ethIfaceId}},
+ callback{std::forward<CallbackFunc>(callback)}](
const boost::system::error_code error,
const dbus::utility::ManagedObjectType& resp) {
EthernetInterfaceData ethData{};
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index c19bef5..41b14f8 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -82,7 +82,7 @@
void getEthernetIfaceData(CallbackFunc&& callback)
{
crow::connections::systemBus->async_method_call(
- [callback{std::move(callback)}](
+ [callback{std::forward<CallbackFunc>(callback)}](
const boost::system::error_code errorCode,
const dbus::utility::ManagedObjectType& dbusData) {
std::vector<std::string> ntpServers;
diff --git a/redfish-core/lib/redfish_util.hpp b/redfish-core/lib/redfish_util.hpp
index b631f91..881bf1a 100644
--- a/redfish-core/lib/redfish_util.hpp
+++ b/redfish-core/lib/redfish_util.hpp
@@ -94,9 +94,9 @@
CallbackFunc&& callback)
{
crow::connections::systemBus->async_method_call(
- [serviceName,
- callback{std::move(callback)}](const boost::system::error_code ec,
- const std::vector<UnitStruct>& r) {
+ [serviceName, callback{std::forward<CallbackFunc>(callback)}](
+ const boost::system::error_code ec,
+ const std::vector<UnitStruct>& r) {
if (ec)
{
BMCWEB_LOG_ERROR << ec;
@@ -174,7 +174,7 @@
std::vector<std::tuple<std::string, std::string>>>(
*crow::connections::systemBus, "org.freedesktop.systemd1", socketPath,
"org.freedesktop.systemd1.Socket", "Listen",
- [callback{std::move(callback)}](
+ [callback{std::forward<CallbackFunc>(callback)}](
const boost::system::error_code ec,
const std::vector<std::tuple<std::string, std::string>>& resp) {
if (ec)
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index de0a828..6d10bb7 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -327,7 +327,8 @@
"xyz.openbmc_project.Sensor.Value"};
// Response handler for parsing objects subtree
- auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
+ auto respHandler = [callback{std::forward<Callback>(callback)},
+ sensorsAsyncResp,
sensorNames](const boost::system::error_code ec,
const GetSubTreeType& subtree) {
BMCWEB_LOG_DEBUG << "getObjectsWithConnection resp_handler enter";
@@ -466,7 +467,7 @@
"xyz.openbmc_project.Inventory.Item.Chassis"};
auto respHandler =
- [callback{std::move(callback)},
+ [callback{std::forward<Callback>(callback)},
asyncResp](const boost::system::error_code ec,
const std::vector<std::string>& chassisPaths) mutable {
BMCWEB_LOG_DEBUG << "getValidChassisPath respHandler enter";
@@ -520,7 +521,8 @@
const std::array<const char*, 2> interfaces = {
"xyz.openbmc_project.Inventory.Item.Board",
"xyz.openbmc_project.Inventory.Item.Chassis"};
- auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp](
+ auto respHandler = [callback{std::forward<Callback>(callback)},
+ sensorsAsyncResp](
const boost::system::error_code ec,
const std::vector<std::string>& chassisPaths) {
BMCWEB_LOG_DEBUG << "getChassis respHandler enter";
@@ -596,7 +598,8 @@
sdbusplus::asio::getProperty<std::vector<std::string>>(
*crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper",
sensorPath, "xyz.openbmc_project.Association", "endpoints",
- [sensorsAsyncResp, callback{std::move(callback)}](
+ [sensorsAsyncResp,
+ callback{std::forward<const Callback>(callback)}](
const boost::system::error_code& e,
const std::vector<std::string>& nodeSensorList) {
if (e)
@@ -653,7 +656,7 @@
"org.freedesktop.DBus.ObjectManager"};
// Response handler for GetSubTree DBus method
- auto respHandler = [callback{std::move(callback)},
+ auto respHandler = [callback{std::forward<Callback>(callback)},
sensorsAsyncResp](const boost::system::error_code ec,
const GetSubTreeType& subtree) {
BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler enter";
@@ -1602,7 +1605,8 @@
// Response handler for GetManagedObjects
auto respHandler = [sensorsAsyncResp, inventoryItems, invConnections,
- objectMgrPaths, callback{std::move(callback)},
+ objectMgrPaths,
+ callback{std::forward<Callback>(callback)},
invConnectionsIndex](
const boost::system::error_code ec,
dbus::utility::ManagedObjectType& resp) {
@@ -1691,7 +1695,8 @@
"xyz.openbmc_project.State.Decorator.OperationalStatus"};
// Response handler for parsing output from GetSubTree
- auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
+ auto respHandler = [callback{std::forward<Callback>(callback)},
+ sensorsAsyncResp,
inventoryItems](const boost::system::error_code ec,
const GetSubTreeType& subtree) {
BMCWEB_LOG_DEBUG << "getInventoryItemsConnections respHandler enter";
@@ -1773,7 +1778,8 @@
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations enter";
// Response handler for GetManagedObjects
- auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
+ auto respHandler = [callback{std::forward<Callback>(callback)},
+ sensorsAsyncResp,
sensorNames](const boost::system::error_code ec,
dbus::utility::ManagedObjectType& resp) {
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler enter";
@@ -1955,7 +1961,7 @@
// Response handler for Get State property
auto respHandler =
[sensorsAsyncResp, inventoryItems, ledConnections, ledPath,
- callback{std::move(callback)}, ledConnectionsIndex](
+ callback{std::forward<Callback>(callback)}, ledConnectionsIndex](
const boost::system::error_code ec, const std::string& state) {
BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter";
if (ec)
@@ -2044,7 +2050,8 @@
"xyz.openbmc_project.Led.Physical"};
// Response handler for parsing output from GetSubTree
- auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
+ auto respHandler = [callback{std::forward<Callback>(callback)},
+ sensorsAsyncResp,
inventoryItems](const boost::system::error_code ec,
const GetSubTreeType& subtree) {
BMCWEB_LOG_DEBUG << "getInventoryLeds respHandler enter";
@@ -2141,7 +2148,7 @@
// Response handler for Get DeratingFactor property
auto respHandler = [sensorsAsyncResp, inventoryItems,
- callback{std::move(callback)}](
+ callback{std::forward<Callback>(callback)}](
const boost::system::error_code ec,
const uint32_t value) {
BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler enter";
@@ -2221,7 +2228,8 @@
"xyz.openbmc_project.Control.PowerSupplyAttributes"};
// Response handler for parsing output from GetSubTree
- auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
+ auto respHandler = [callback{std::forward<Callback>(callback)},
+ sensorsAsyncResp,
inventoryItems](const boost::system::error_code ec,
const GetSubTreeType& subtree) {
BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes respHandler enter";
@@ -2313,12 +2321,13 @@
{
BMCWEB_LOG_DEBUG << "getInventoryItems enter";
auto getInventoryItemAssociationsCb =
- [sensorsAsyncResp, objectMgrPaths, callback{std::move(callback)}](
+ [sensorsAsyncResp, objectMgrPaths,
+ callback{std::forward<Callback>(callback)}](
std::shared_ptr<std::vector<InventoryItem>> inventoryItems) {
BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb enter";
auto getInventoryItemsConnectionsCb =
[sensorsAsyncResp, inventoryItems, objectMgrPaths,
- callback{std::move(callback)}](
+ callback{std::forward<const Callback>(callback)}](
std::shared_ptr<boost::container::flat_set<std::string>>
invConnections) {
BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb enter";