diff options
author | Ed Tanous <edtanous@google.com> | 2022-01-25 21:19:23 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-02-09 23:45:00 +0300 |
commit | 9eb808c1a84a76e92b0e01fa95d3f160f38d7c3f (patch) | |
tree | f3631a3f2a97fb0f048fb1dd5d295b867e8d37fc | |
parent | b3db89663256a462e9c90bf260d5058014765137 (diff) | |
download | bmcweb-9eb808c1a84a76e92b0e01fa95d3f160f38d7c3f.tar.xz |
Enable readability-avoid-const-params-in-decls
This check involves explicitly declaring variables const when they're
declared auto, which helps in readability, and makes it more clear that
the variables are const.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I71198ea03850384a389a56ad26f2c4a48c75b148
24 files changed, 71 insertions, 64 deletions
diff --git a/.clang-tidy b/.clang-tidy index 0a7f665751..953c78e780 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -267,6 +267,7 @@ performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param, +readability-avoid-const-params-in-decls, readability-braces-around-statements, readability-const-return-type, readability-container-size-empty, diff --git a/http/common.hpp b/http/common.hpp index 6f6b24c0ae..01e90b2a71 100644 --- a/http/common.hpp +++ b/http/common.hpp @@ -48,7 +48,7 @@ struct RoutingParams std::cerr << i << ", "; } std::cerr << std::endl; - for (auto& i : stringParams) + for (const std::string& i : stringParams) { std::cerr << i << ", "; } diff --git a/http/http_connection.hpp b/http/http_connection.hpp index 84f5c18ece..0b58e9b6f5 100644 --- a/http/http_connection.hpp +++ b/http/http_connection.hpp @@ -99,8 +99,9 @@ class Connection : adaptor.set_verify_mode(boost::asio::ssl::verify_peer); std::string id = "bmcweb"; + const char* cStr = id.c_str(); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - auto* idC = reinterpret_cast<const unsigned char*>(id.c_str()); + const auto* idC = reinterpret_cast<const unsigned char*>(cStr); int ret = SSL_set_session_id_context( adaptor.native_handle(), idC, static_cast<unsigned int>(id.length())); diff --git a/http/routing.hpp b/http/routing.hpp index 9cd3d7b3f6..9032b148e2 100644 --- a/http/routing.hpp +++ b/http/routing.hpp @@ -68,7 +68,7 @@ class BaseRule } #endif - size_t getMethods() + size_t getMethods() const { return methodsBitfield; } diff --git a/http/websocket.hpp b/http/websocket.hpp index 74bce581d2..eadb276c0c 100644 --- a/http/websocket.hpp +++ b/http/websocket.hpp @@ -34,11 +34,11 @@ struct Connection : std::enable_shared_from_this<Connection> Connection& operator=(const Connection&) = delete; Connection& operator=(const Connection&&) = delete; - virtual void sendBinary(const std::string_view msg) = 0; + virtual void sendBinary(std::string_view msg) = 0; virtual void sendBinary(std::string&& msg) = 0; - virtual void sendText(const std::string_view msg) = 0; + virtual void sendText(std::string_view msg) = 0; virtual void sendText(std::string&& msg) = 0; - virtual void close(const std::string_view msg = "quit") = 0; + virtual void close(std::string_view msg = "quit") = 0; virtual boost::asio::io_context& getIoContext() = 0; virtual ~Connection() = default; diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp index 10f0a9a66b..b39bada519 100644 --- a/include/ibm/locks.hpp +++ b/include/ibm/locks.hpp @@ -245,7 +245,7 @@ inline RcAcquireLock Lock::acquireLock(const LockRequests& lockRequestStructure) // validate the lock request - for (auto& lockRecord : lockRequestStructure) + for (const auto& lockRecord : lockRequestStructure) { bool status = isValidLockRequest(lockRecord); if (!status) diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp index 876ceb3d18..e80e727210 100644 --- a/include/ibm/management_console_rest.hpp +++ b/include/ibm/management_console_rest.hpp @@ -85,7 +85,7 @@ inline void handleFilePut(const crow::Request& req, return; } std::uintmax_t saveAreaDirSize = 0; - for (auto& it : iter) + for (const auto& it : iter) { if (!std::filesystem::is_directory(it, ec)) { diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 9233a278f8..8aab757d48 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -2232,7 +2232,7 @@ inline void requestRoutes(App& app) } std::filesystem::directory_iterator files(loc); - for (auto& file : files) + for (const auto& file : files) { std::ifstream readFile(file.path()); if (!readFile.good()) diff --git a/include/random.hpp b/include/random.hpp index 0e63391aad..082c4e3008 100644 --- a/include/random.hpp +++ b/include/random.hpp @@ -29,7 +29,7 @@ struct OpenSSLGenerator return std::numeric_limits<uint8_t>::min(); } - bool error() + bool error() const { return err; } diff --git a/include/sessions.hpp b/include/sessions.hpp index b445915e34..85c0cb9208 100644 --- a/include/sessions.hpp +++ b/include/sessions.hpp @@ -353,7 +353,7 @@ class SessionStore return authMethodsConfig; } - bool needsWrite() + bool needsWrite() const { return needWrite; } diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp index 8aa6ba6474..dcca3aa93e 100644 --- a/redfish-core/include/error_messages.hpp +++ b/redfish-core/include/error_messages.hpp @@ -91,7 +91,7 @@ void actionParameterValueFormatError(crow::Response& res, * @returns Message InternalError formatted to JSON */ nlohmann::json internalError(); -void internalError(crow::Response& res, const bmcweb::source_location location = +void internalError(crow::Response& res, bmcweb::source_location location = bmcweb::source_location::current()); /** diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 4fb07ca235..ec294ae200 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -555,7 +555,7 @@ class Subscription : public persistent_data::UserSubscription } } - uint64_t getEventSeqNum() + uint64_t getEventSeqNum() const { return eventSeqNum; } @@ -751,7 +751,7 @@ class EventServiceManager } } - void updateSubscriptionData() + void updateSubscriptionData() const { persistent_data::EventServiceStore::getInstance() .eventServiceConfig.enabled = serviceEnabled; diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp index f5bc8b68c2..160816fd93 100644 --- a/redfish-core/include/privileges.hpp +++ b/redfish-core/include/privileges.hpp @@ -260,7 +260,7 @@ inline bool isOperationAllowedWithPrivileges( { return true; } - for (auto& requiredPrivileges : operationPrivilegesRequired) + for (const auto& requiredPrivileges : operationPrivilegesRequired) { BMCWEB_LOG_DEBUG << "Checking operation privileges..."; if (userPrivileges.isSupersetOf(requiredPrivileges)) diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp index a0758d925c..c05f8cbb05 100644 --- a/redfish-core/include/utils/fw_utils.hpp +++ b/redfish-core/include/utils/fw_utils.hpp @@ -68,7 +68,7 @@ inline void // example functionalFw: // v as 2 "/xyz/openbmc_project/software/ace821ef" // "/xyz/openbmc_project/software/230fb078" - for (auto& fw : functionalFw) + for (const auto& fw : functionalFw) { sdbusplus::message::object_path path(fw); std::string leaf = path.filename(); diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index ecc2e9c83f..87707825ea 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -185,7 +185,7 @@ inline void parseLDAPConfigData(nlohmann::json& jsonResponse, nlohmann::json& roleMapArray = jsonResponse[ldapType]["RemoteRoleMapping"]; roleMapArray = nlohmann::json::array(); - for (auto& obj : confData.groupRoleList) + for (const auto& obj : confData.groupRoleList) { BMCWEB_LOG_DEBUG << "Pushing the data groupName=" << obj.second.groupName << "\n"; @@ -1539,7 +1539,7 @@ inline void requestAccountServiceRoutes(App& app) asyncResp->res.jsonValue["Members"]; memberArray = nlohmann::json::array(); - for (auto& userpath : users) + for (const auto& userpath : users) { std::string user = userpath.first.filename(); if (user.empty()) diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp index 34f6770da5..23e3eadceb 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -952,7 +952,7 @@ inline void } nlohmann::json& links = asyncResp->res.jsonValue["Links"]["Certificates"]; - for (auto& cert : certs) + for (const auto& cert : certs) { long id = getIDFromURL(cert.first.str); if (id >= 0) diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index e4e5eb9d62..f4260a8217 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -450,7 +450,7 @@ inline void // Check if proper pattern for object path appears if (boost::starts_with(objpath.first.str, ipv6PathStart)) { - for (auto& interface : objpath.second) + for (const auto& interface : objpath.second) { if (interface.first == "xyz.openbmc_project.Network.IP") { @@ -463,7 +463,7 @@ inline void IPv6AddressData& ipv6Address = *it.first; ipv6Address.id = objpath.first.str.substr(ipv6PathStart.size()); - for (auto& property : interface.second) + for (const auto& property : interface.second) { if (property.first == "Address") { @@ -528,7 +528,7 @@ inline void // Check if proper pattern for object path appears if (boost::starts_with(objpath.first.str, ipv4PathStart)) { - for (auto& interface : objpath.second) + for (const auto& interface : objpath.second) { if (interface.first == "xyz.openbmc_project.Network.IP") { @@ -541,7 +541,7 @@ inline void IPv4AddressData& ipv4Address = *it.first; ipv4Address.id = objpath.first.str.substr(ipv4PathStart.size()); - for (auto& property : interface.second) + for (const auto& property : interface.second) { if (property.first == "Address") { @@ -1782,7 +1782,7 @@ inline void parseInterfaceData( nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"]; ipv4Array = nlohmann::json::array(); ipv4StaticArray = nlohmann::json::array(); - for (auto& ipv4Config : ipv4Data) + for (const auto& ipv4Config : ipv4Data) { std::string gatewayStr = ipv4Config.gateway; @@ -1819,7 +1819,7 @@ inline void parseInterfaceData( nlohmann::json& ipv6AddrPolicyTable = jsonResponse["IPv6AddressPolicyTable"]; ipv6AddrPolicyTable = nlohmann::json::array(); - for (auto& ipv6Config : ipv6Data) + for (const auto& ipv6Config : ipv6Data) { ipv6Array.push_back({{"Address", ipv6Config.address}, {"PrefixLength", ipv6Config.prefixLength}, diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp index 76032b3fe7..588cf13ffb 100644 --- a/redfish-core/lib/hypervisor_system.hpp +++ b/redfish-core/lib/hypervisor_system.hpp @@ -208,7 +208,7 @@ inline bool extractHypervisorInterfaceData( IPv4AddressData& ipv4Address = *it.first; if (ifacePair.first == "xyz.openbmc_project.Object.Enable") { - for (auto& property : ifacePair.second) + for (const auto& property : ifacePair.second) { if (property.first == "Enabled") { @@ -224,7 +224,7 @@ inline bool extractHypervisorInterfaceData( } if (ifacePair.first == "xyz.openbmc_project.Network.IP") { - for (auto& property : ifacePair.second) + for (const auto& property : ifacePair.second) { if (property.first == "Address") { @@ -497,7 +497,7 @@ inline void parseInterfaceData( nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"]; ipv4Array = nlohmann::json::array(); ipv4StaticArray = nlohmann::json::array(); - for (auto& ipv4Config : ipv4Data) + for (const auto& ipv4Config : ipv4Data) { if (ipv4Config.isActive) { diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 9f40725d61..aa4d5ec49e 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -428,7 +428,7 @@ inline void if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") { - for (auto& propertyMap : interfaceMap.second) + for (const auto& propertyMap : interfaceMap.second) { if (propertyMap.first == "Status") { @@ -467,7 +467,7 @@ inline void "xyz.openbmc_project.Time.EpochTime") { - for (auto& propertyMap : interfaceMap.second) + for (const auto& propertyMap : interfaceMap.second) { if (propertyMap.first == "Elapsed") { @@ -564,7 +564,7 @@ inline void std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/"; - for (auto& objectPath : resp) + for (const auto& objectPath : resp) { if (objectPath.first.str != dumpEntryPath + entryID) { @@ -576,17 +576,18 @@ inline void uint64_t size = 0; std::string dumpStatus; - for (auto& interfaceMap : objectPath.second) + for (const auto& interfaceMap : objectPath.second) { if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") { - for (auto& propertyMap : interfaceMap.second) + for (const auto& propertyMap : interfaceMap.second) { if (propertyMap.first == "Status") { - auto status = std::get_if<std::string>( - &propertyMap.second); + const std::string* status = + std::get_if<std::string>( + &propertyMap.second); if (status == nullptr) { messages::internalError(asyncResp->res); @@ -599,11 +600,11 @@ inline void else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") { - for (auto& propertyMap : interfaceMap.second) + for (const auto& propertyMap : interfaceMap.second) { if (propertyMap.first == "Size") { - auto sizePtr = + const uint64_t* sizePtr = std::get_if<uint64_t>(&propertyMap.second); if (sizePtr == nullptr) { @@ -618,7 +619,7 @@ inline void else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") { - for (auto& propertyMap : interfaceMap.second) + for (const auto& propertyMap : interfaceMap.second) { if (propertyMap.first == "Elapsed") { @@ -1373,7 +1374,7 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; entriesArray = nlohmann::json::array(); - for (auto& objectPath : resp) + for (const auto& objectPath : resp) { const uint32_t* id = nullptr; const uint64_t* timestamp = nullptr; @@ -1382,12 +1383,13 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) const std::string* message = nullptr; const std::string* filePath = nullptr; bool resolved = false; - for (auto& interfaceMap : objectPath.second) + for (const auto& interfaceMap : objectPath.second) { if (interfaceMap.first == "xyz.openbmc_project.Logging.Entry") { - for (auto& propertyMap : interfaceMap.second) + for (const auto& propertyMap : + interfaceMap.second) { if (propertyMap.first == "Id") { @@ -1439,7 +1441,8 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) else if (interfaceMap.first == "xyz.openbmc_project.Common.FilePath") { - for (auto& propertyMap : interfaceMap.second) + for (const auto& propertyMap : + interfaceMap.second) { if (propertyMap.first == "Path") { @@ -1536,7 +1539,7 @@ inline void requestRoutesDBusEventLogEntry(App& app) const std::string* filePath = nullptr; bool resolved = false; - for (auto& propertyMap : resp) + for (const auto& propertyMap : resp) { if (propertyMap.first == "Id") { @@ -3423,7 +3426,7 @@ inline void requestRoutesPostCodesEntryAdditionalData(App& app) return; } - auto& [tID, c] = postcodes[value]; + const auto& [tID, c] = postcodes[value]; if (c.empty()) { BMCWEB_LOG_INFO << "No found post code data"; diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp index 9a805f0036..c69af7ece5 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp @@ -1214,7 +1214,7 @@ struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> } const std::string* current = nullptr; const std::vector<std::string>* supported = nullptr; - for (auto& [key, value] : resp) + for (const auto& [key, value] : resp) { if (key == "Current") { @@ -1439,7 +1439,7 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> } const std::string* current = nullptr; const std::vector<std::string>* supported = nullptr; - for (auto& [key, value] : r) + for (const auto& [key, value] : r) { if (key == "Current") { diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp index f933cd46b6..89bd8dbe45 100644 --- a/redfish-core/lib/metric_report.hpp +++ b/redfish-core/lib/metric_report.hpp @@ -22,7 +22,7 @@ inline nlohmann::json toMetricValues(const Readings& readings) { nlohmann::json metricValues = nlohmann::json::array_t(); - for (auto& [id, metadata, sensorValue, timestamp] : readings) + for (const auto& [id, metadata, sensorValue, timestamp] : readings) { metricValues.push_back({ {"MetricId", id}, diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp index 745fad8186..541e631ffa 100644 --- a/redfish-core/lib/metric_report_definition.hpp +++ b/redfish-core/lib/metric_report_definition.hpp @@ -86,7 +86,7 @@ inline void fillReportDefinition( } nlohmann::json metrics = nlohmann::json::array(); - for (auto& [sensorPath, operationType, id, metadata] : *readingParams) + for (const auto& [sensorPath, operationType, id, metadata] : *readingParams) { metrics.push_back({ {"MetricId", id}, diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index 121223efc6..f3fa52c6fe 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -761,11 +761,11 @@ inline std::string // Check if sensor has critical threshold alarm - for (auto& [interface, values] : interfacesDict) + for (const auto& [interface, values] : interfacesDict) { if (interface == "xyz.openbmc_project.Sensor.Threshold.Critical") { - for (auto& [valueName, value] : values) + for (const auto& [valueName, value] : values) { if (valueName == "CriticalAlarmHigh" || valueName == "CriticalAlarmLow") @@ -798,11 +798,11 @@ inline std::string } // Check if sensor has warning threshold alarm - for (auto& [interface, values] : interfacesDict) + for (const auto& [interface, values] : interfacesDict) { if (interface == "xyz.openbmc_project.Sensor.Threshold.Warning") { - for (auto& [valueName, value] : values) + for (const auto& [valueName, value] : values) { if (valueName == "WarningAlarmHigh" || valueName == "WarningAlarmLow") @@ -866,11 +866,11 @@ inline void objectInterfacesToJson( { // Assume values exist as is (10^0 == 1) if no scale exists int64_t scaleMultiplier = 0; - for (auto& [interface, values] : interfacesDict) + for (const auto& [interface, values] : interfacesDict) { if (interface == "xyz.openbmc_project.Sensor.Value") { - for (auto& [valueName, value] : values) + for (const auto& [valueName, value] : values) { if (valueName == "Scale") { @@ -1194,13 +1194,15 @@ inline void populateFanRedundancy( return; } - auto allowedFailures = std::get_if<uint8_t>( - &(findFailures->second)); - auto collection = + const uint8_t* allowedFailures = + std::get_if<uint8_t>( + &(findFailures->second)); + const std::vector<std::string>* collection = std::get_if<std::vector<std::string>>( &(findCollection->second)); - auto status = std::get_if<std::string>( - &(findStatus->second)); + const std::string* status = + std::get_if<std::string>( + &(findStatus->second)); if (allowedFailures == nullptr || collection == nullptr || status == nullptr) @@ -1467,11 +1469,11 @@ inline void storeInventoryItemData( { // Get properties from Inventory.Item interface - for (auto& [interface, values] : interfacesDict) + for (const auto& [interface, values] : interfacesDict) { if (interface == "xyz.openbmc_project.Inventory.Item") { - for (auto& [name, dbusValue] : values) + for (const auto& [name, dbusValue] : values) { if (name == "Present") { @@ -1493,7 +1495,7 @@ inline void storeInventoryItemData( // Get properties from Inventory.Decorator.Asset interface if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") { - for (auto& [name, dbusValue] : values) + for (const auto& [name, dbusValue] : values) { if (name == "Manufacturer") { @@ -1537,7 +1539,7 @@ inline void storeInventoryItemData( if (interface == "xyz.openbmc_project.State.Decorator.OperationalStatus") { - for (auto& [name, dbusValue] : values) + for (const auto& [name, dbusValue] : values) { if (name == "Functional") { diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index 3137ab316e..ba92748b3c 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -723,7 +723,7 @@ inline void requestRoutesSoftwareInventoryCollection(App& app) nlohmann::json::array(); asyncResp->res.jsonValue["Members@odata.count"] = 0; - for (auto& obj : subtree) + for (const auto& obj : subtree) { sdbusplus::message::object_path path(obj.first); std::string swId = path.filename(); |