clang-tidy: Enable readability-qualified-auto check
This check aims to improve code readability by suggesting the use
of const auto * instead of auto for variables that are pointers
or iterators. This helps clarify the const-ness of the pointed-to
object or container elements.
Change-Id: I5fa46006aa5669834ebb144d32014f8882e563e3
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/.clang-tidy b/.clang-tidy
index a5f42b6..fed8f0d 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -255,6 +255,7 @@
readability-misplaced-array-index,
readability-named-parameter,
readability-non-const-parameter,
+readability-qualified-auto,
readability-redundant-access-specifiers,
readability-redundant-function-ptr-dereference,
readability-redundant-member-init,
diff --git a/bmc_state_manager.cpp b/bmc_state_manager.cpp
index 22f2a42..bbea272 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -266,7 +266,7 @@
{
uint64_t bootReason = 0;
std::ifstream file;
- auto bootstatusPath = "/sys/class/watchdog/watchdog0/bootstatus";
+ const auto* bootstatusPath = "/sys/class/watchdog/watchdog0/bootstatus";
file.exceptions(std::ifstream::failbit | std::ifstream::badbit |
std::ifstream::eofbit);
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 388ac64..27d3e27 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -141,7 +141,7 @@
void Host::executeTransition(Transition tranReq)
{
- auto& sysdUnit = getTarget(tranReq);
+ const auto& sysdUnit = getTarget(tranReq);
auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
SYSTEMD_INTERFACE, "StartUnit");
diff --git a/scheduled_host_transition.cpp b/scheduled_host_transition.cpp
index 6f9edec..077d794 100644
--- a/scheduled_host_transition.cpp
+++ b/scheduled_host_transition.cpp
@@ -241,7 +241,7 @@
uint32_t /* revents */,
void* userdata)
{
- auto schedHostTran = static_cast<ScheduledHostTransition*>(userdata);
+ auto* schedHostTran = static_cast<ScheduledHostTransition*>(userdata);
std::array<char, 64> time{};
diff --git a/systemd_service_parser.cpp b/systemd_service_parser.cpp
index 46d9156..3258b36 100644
--- a/systemd_service_parser.cpp
+++ b/systemd_service_parser.cpp
@@ -15,7 +15,7 @@
std::ifstream fileStream(jsonFile);
auto j = json::parse(fileStream);
- for (auto& service : j["services"].items())
+ for (const auto& service : j["services"].items())
{
if (gVerbose)
{
diff --git a/systemd_target_monitor.cpp b/systemd_target_monitor.cpp
index a0fea9e..44841c8 100644
--- a/systemd_target_monitor.cpp
+++ b/systemd_target_monitor.cpp
@@ -20,7 +20,7 @@
{
std::cout << target << " " << value.errorToLog << std::endl;
std::cout << " ";
- for (auto& eToMonitor : value.errorsToMonitor)
+ for (const auto& eToMonitor : value.errorsToMonitor)
{
std::cout << eToMonitor << ", ";
}