Fix moves/forward

Clang has new checks for std::move/std::forward correctness, which
catches quite a few "wrong" things where we were making copies of
callback handlers.

Unfortunately, the lambda syntax of

callback{std::forward<Callback>(callback)}

in a capture confuses it, so change usages to
callback = std::forward<Callback>(callback)

to be consistent.

Tested: Redfish service validator passes.

Change-Id: I7a111ec00cf78ecb7d5f5b102c786c1c14d74384
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/include/utils/chassis_utils.hpp b/redfish-core/include/utils/chassis_utils.hpp
index 6d1f8d1..410a289 100644
--- a/redfish-core/include/utils/chassis_utils.hpp
+++ b/redfish-core/include/utils/chassis_utils.hpp
@@ -29,7 +29,7 @@
     // Get the Chassis Collection
     dbus::utility::getSubTreePaths(
         "/xyz/openbmc_project/inventory", 0, interfaces,
-        [callback{std::forward<Callback>(callback)}, asyncResp,
+        [callback = std::forward<Callback>(callback), asyncResp,
          chassisId](const boost::system::error_code& ec,
                     const dbus::utility::MapperGetSubTreePathsResponse&
                         chassisPaths) mutable {
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 3a1869f..47fb58d 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -513,7 +513,7 @@
 
     dbus::utility::getDbusObject(
         ldapConfigObjectName, interfaces,
-        [callback,
+        [callback = std::forward<CallbackFunc>(callback),
          ldapType](const boost::system::error_code& ec,
                    const dbus::utility::MapperGetObject& resp) mutable {
         if (ec || resp.empty())
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 2d538d7..876bc2e 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1111,7 +1111,7 @@
     dbus::utility::getManagedObjects(
         "xyz.openbmc_project.Network", path,
         [ethifaceId{std::string{ethifaceId}},
-         callback{std::forward<CallbackFunc>(callback)}](
+         callback = std::forward<CallbackFunc>(callback)](
             const boost::system::error_code& ec,
             const dbus::utility::ManagedObjectType& resp) mutable {
         EthernetInterfaceData ethData{};
@@ -1166,7 +1166,7 @@
     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
     dbus::utility::getManagedObjects(
         "xyz.openbmc_project.Network", path,
-        [callback{std::forward<CallbackFunc>(callback)}](
+        [callback = std::forward<CallbackFunc>(callback)](
             const boost::system::error_code& ec,
             const 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 1a3d6cb..2b3714b 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -315,7 +315,7 @@
     dbus::utility::getManagedObjects(
         "xyz.openbmc_project.Settings", path,
         [ethIfaceId{std::string{ethIfaceId}},
-         callback{std::forward<CallbackFunc>(callback)}](
+         callback = std::forward<CallbackFunc>(callback)](
             const boost::system::error_code& ec,
             const dbus::utility::ManagedObjectType& resp) mutable {
         EthernetInterfaceData ethData{};
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 6ea165d..f27785d 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -960,7 +960,7 @@
     }
 
     crow::connections::systemBus->async_method_call(
-        [asyncResp, payload, createdObjPath,
+        [asyncResp, payload = std::move(payload), createdObjPath,
          dumpEntryPath{std::move(dumpEntryPath)},
          dumpId](const boost::system::error_code& ec,
                  const std::string& introspectXml) {
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 31fc5af..d864e22 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -101,7 +101,7 @@
     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
     dbus::utility::getManagedObjects(
         "xyz.openbmc_project.Network", path,
-        [callback{std::forward<CallbackFunc>(callback)}](
+        [callback = std::forward<CallbackFunc>(callback)](
             const boost::system::error_code& ec,
             const dbus::utility::ManagedObjectType& dbusData) {
         std::vector<std::string> ntpServers;
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index e8da219..9392916 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -221,7 +221,7 @@
     dbus::utility::getAssociatedSubTreePaths(
         associationPath, sdbusplus::message::object_path(inventoryPath), 0,
         pcieSlotInterface,
-        [callback, asyncResp, pcieDevicePath](
+        [callback = std::move(callback), asyncResp, pcieDevicePath](
             const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreePathsResponse& endpoints) {
         if (ec)
diff --git a/redfish-core/lib/redfish_util.hpp b/redfish-core/lib/redfish_util.hpp
index 7a96481..5d8c0e6 100644
--- a/redfish-core/lib/redfish_util.hpp
+++ b/redfish-core/lib/redfish_util.hpp
@@ -69,7 +69,7 @@
         "xyz.openbmc_project.Inventory.Item.Chassis"};
     dbus::utility::getSubTree(
         "/xyz/openbmc_project/inventory", 0, interfaces,
-        [callback,
+        [callback = std::forward<CallbackFunc>(callback),
          asyncResp](const boost::system::error_code& ec,
                     const dbus::utility::MapperGetSubTreeResponse& subtree) {
         if (ec)
@@ -104,7 +104,7 @@
     CallbackFunc&& callback)
 {
     crow::connections::systemBus->async_method_call(
-        [protocolToDBus, callback{std::forward<CallbackFunc>(callback)}](
+        [protocolToDBus, callback = std::forward<CallbackFunc>(callback)](
             const boost::system::error_code& ec,
             const std::vector<UnitStruct>& r) {
         std::vector<std::tuple<std::string, std::string, bool>> socketData;
@@ -211,7 +211,7 @@
         std::vector<std::tuple<std::string, std::string>>>(
         *crow::connections::systemBus, "org.freedesktop.systemd1", socketPath,
         "org.freedesktop.systemd1.Socket", "Listen",
-        [callback{std::forward<CallbackFunc>(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 8506185..75eaa7c 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -361,7 +361,7 @@
     // Make call to ObjectMapper to find all sensors objects
     dbus::utility::getSubTree(
         path, 2, interfaces,
-        [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
+        [callback = std::forward<Callback>(callback), sensorsAsyncResp,
          sensorNames](const boost::system::error_code& ec,
                       const dbus::utility::MapperGetSubTreeResponse& subtree) {
         // Response handler for parsing objects subtree
@@ -423,9 +423,10 @@
                     Callback&& callback)
 {
     auto objectsWithConnectionCb =
-        [callback](const std::set<std::string>& connections,
-                   const std::set<std::pair<std::string, std::string>>&
-                   /*objectsWithConnection*/) { callback(connections); };
+        [callback = std::forward<Callback>(callback)](
+            const std::set<std::string>& connections,
+            const std::set<std::pair<std::string, std::string>>&
+            /*objectsWithConnection*/) { callback(connections); };
     getObjectsWithConnection(sensorsAsyncResp, sensorNames,
                              std::move(objectsWithConnectionCb));
 }
@@ -524,7 +525,7 @@
     // Get the Chassis Collection
     dbus::utility::getSubTreePaths(
         "/xyz/openbmc_project/inventory", 0, interfaces,
-        [callback{std::forward<Callback>(callback)}, asyncResp,
+        [callback = std::forward<Callback>(callback), asyncResp,
          chassisIdStr{std::string(chassisId)},
          chassisSubNode{std::string(chassisSubNode)}, sensorTypes](
             const boost::system::error_code& ec,
@@ -567,7 +568,7 @@
         dbus::utility::getAssociationEndPoints(
             sensorPath,
             [asyncResp, chassisSubNode, sensorTypes,
-             callback{std::forward<const Callback>(callback)}](
+             callback = std::forward<const Callback>(callback)](
                 const boost::system::error_code& ec2,
                 const dbus::utility::MapperEndPoints& nodeSensorList) {
             if (ec2)
@@ -1474,7 +1475,7 @@
         dbus::utility::getManagedObjects(
             invConnection, path,
             [sensorsAsyncResp, inventoryItems, invConnections,
-             callback{std::forward<Callback>(callback)}, invConnectionsIndex](
+             callback = std::forward<Callback>(callback), invConnectionsIndex](
                 const boost::system::error_code& ec,
                 const dbus::utility::ManagedObjectType& resp) {
             BMCWEB_LOG_DEBUG("getInventoryItemsData respHandler enter");
@@ -1550,7 +1551,7 @@
     // Make call to ObjectMapper to find all inventory items
     dbus::utility::getSubTree(
         path, 0, interfaces,
-        [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
+        [callback = std::forward<Callback>(callback), sensorsAsyncResp,
          inventoryItems](
             const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreeResponse& subtree) {
@@ -1626,7 +1627,7 @@
     sdbusplus::message::object_path path("/");
     dbus::utility::getManagedObjects(
         "xyz.openbmc_project.ObjectMapper", path,
-        [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
+        [callback = std::forward<Callback>(callback), sensorsAsyncResp,
          sensorNames](const boost::system::error_code& ec,
                       const dbus::utility::ManagedObjectType& resp) {
         BMCWEB_LOG_DEBUG("getInventoryItemAssociations respHandler enter");
@@ -1795,7 +1796,7 @@
         // Response handler for Get State property
         auto respHandler =
             [sensorsAsyncResp, inventoryItems, ledConnections, ledPath,
-             callback{std::forward<Callback>(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)
@@ -1886,7 +1887,7 @@
     // Make call to ObjectMapper to find all inventory items
     dbus::utility::getSubTree(
         path, 0, interfaces,
-        [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
+        [callback = std::forward<Callback>(callback), sensorsAsyncResp,
          inventoryItems](
             const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreeResponse& subtree) {
@@ -1976,7 +1977,7 @@
 
     // Response handler for Get DeratingFactor property
     auto respHandler = [sensorsAsyncResp, inventoryItems,
-                        callback{std::forward<Callback>(callback)}](
+                        callback = std::forward<Callback>(callback)](
                            const boost::system::error_code& ec,
                            const uint32_t value) {
         BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData respHandler enter");
@@ -2058,7 +2059,7 @@
     // Make call to ObjectMapper to find the PowerSupplyAttributes service
     dbus::utility::getSubTree(
         "/xyz/openbmc_project", 0, interfaces,
-        [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
+        [callback = std::forward<Callback>(callback), sensorsAsyncResp,
          inventoryItems](
             const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreeResponse& subtree) {
@@ -2142,12 +2143,12 @@
 {
     BMCWEB_LOG_DEBUG("getInventoryItems enter");
     auto getInventoryItemAssociationsCb =
-        [sensorsAsyncResp, callback{std::forward<Callback>(callback)}](
+        [sensorsAsyncResp, callback = std::forward<Callback>(callback)](
             std::shared_ptr<std::vector<InventoryItem>> inventoryItems) {
         BMCWEB_LOG_DEBUG("getInventoryItemAssociationsCb enter");
         auto getInventoryItemsConnectionsCb =
             [sensorsAsyncResp, inventoryItems,
-             callback{std::forward<const Callback>(callback)}](
+             callback = std::forward<const Callback>(callback)](
                 std::shared_ptr<std::set<std::string>> invConnections) {
             BMCWEB_LOG_DEBUG("getInventoryItemsConnectionsCb enter");
             auto getInventoryItemsDataCb = [sensorsAsyncResp, inventoryItems,
@@ -2778,7 +2779,7 @@
 
     auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
     auto callback = [asyncResp,
-                     mapCompleteCb{std::forward<Callback>(mapComplete)}](
+                     mapCompleteCb = std::forward<Callback>(mapComplete)](
                         const boost::beast::http::status status,
                         const std::map<std::string, std::string>& uriToDbus) {
         mapCompleteCb(status, uriToDbus);
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 9784d37..b03f323 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -98,9 +98,9 @@
     sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia");
     dbus::utility::getManagedObjects(
         service, path,
-        [service, resName, asyncResp,
-         handler](const boost::system::error_code& ec,
-                  const dbus::utility::ManagedObjectType& subtree) {
+        [service, resName, asyncResp, handler = std::move(handler)](
+            const boost::system::error_code& ec,
+            const dbus::utility::ManagedObjectType& subtree) {
         if (ec)
         {
             BMCWEB_LOG_DEBUG("DBUS response error");