From 22e75f08faf0c03d444daff432c445484672e8f9 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 30 Jun 2022 18:52:16 +0200 Subject: [PATCH] Fix compiler warnings by not unnecessarily (copy-)constructing loop variables --- lib/base/process.cpp | 3 +-- lib/cli/featureutility.cpp | 4 ++-- lib/icinga/host.cpp | 3 +-- lib/icinga/notification.cpp | 3 +-- lib/livestatus/commandstable.cpp | 6 +++--- lib/perfdata/opentsdbwriter.cpp | 4 ++-- lib/remote/apilistener-configsync.cpp | 4 ++-- lib/remote/consolehandler.cpp | 4 +--- lib/remote/eventqueue.cpp | 6 ++---- tools/mkclass/classcompiler.cpp | 4 ++-- 10 files changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 23b735352..aa6a0259e 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -643,8 +643,7 @@ void Process::IOThreadProc(int tid) #endif /* _WIN32 */ int i = 1; - typedef std::pair kv_pair; - for (const kv_pair& kv : l_Processes[tid]) { + for (auto& kv : l_Processes[tid]) { const Process::Ptr& process = kv.second; #ifdef _WIN32 handles[i] = kv.first; diff --git a/lib/cli/featureutility.cpp b/lib/cli/featureutility.cpp index 3523868c5..94929b5a2 100644 --- a/lib/cli/featureutility.cpp +++ b/lib/cli/featureutility.cpp @@ -58,7 +58,7 @@ int FeatureUtility::EnableFeatures(const std::vector& features) std::vector errors; - for (const String& feature : features) { + for (auto& feature : features) { String source = features_available_dir + "/" + feature + ".conf"; if (!Utility::PathExists(source) ) { @@ -126,7 +126,7 @@ int FeatureUtility::DisableFeatures(const std::vector& features) std::vector errors; - for (const String& feature : features) { + for (auto& feature : features) { String target = features_enabled_dir + "/" + feature + ".conf"; if (!Utility::PathExists(target) ) { diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 5bc0cead7..10cd4b445 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -88,8 +88,7 @@ std::vector Host::GetServices() const std::vector services; services.reserve(m_Services.size()); - typedef std::pair ServicePair; - for (const ServicePair& kv : m_Services) { + for (auto& kv : m_Services) { services.push_back(kv.second); } diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index b8cb62ff0..bec03983d 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -643,8 +643,7 @@ String Notification::NotificationFilterToString(int filter, const std::map sFilters; - typedef std::pair kv_pair; - for (const kv_pair& kv : filterMap) { + for (auto& kv : filterMap) { if (filter & kv.second) sFilters.push_back(kv.first); } diff --git a/lib/livestatus/commandstable.cpp b/lib/livestatus/commandstable.cpp index 3a777d231..82701da81 100644 --- a/lib/livestatus/commandstable.cpp +++ b/lib/livestatus/commandstable.cpp @@ -42,17 +42,17 @@ String CommandsTable::GetPrefix() const void CommandsTable::FetchRows(const AddRowFunction& addRowFn) { - for (const ConfigObject::Ptr& object : ConfigType::GetObjectsByType()) { + for (auto& object : ConfigType::GetObjectsByType()) { if (!addRowFn(object, LivestatusGroupByNone, Empty)) return; } - for (const ConfigObject::Ptr& object : ConfigType::GetObjectsByType()) { + for (auto& object : ConfigType::GetObjectsByType()) { if (!addRowFn(object, LivestatusGroupByNone, Empty)) return; } - for (const ConfigObject::Ptr& object : ConfigType::GetObjectsByType()) { + for (auto& object : ConfigType::GetObjectsByType()) { if (!addRowFn(object, LivestatusGroupByNone, Empty)) return; } diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index 461e1bfdd..1ebc139f4 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -376,8 +376,8 @@ void OpenTsdbWriter::SendMetric(const Checkable::Ptr& checkable, const String& m { String tags_string = ""; - for (const Dictionary::Pair& tag : tags) { - tags_string += " " + tag.first + "=" + Convert::ToString(tag.second); + for (auto& tag : tags) { + tags_string += " " + tag.first + "=" + tag.second; } std::ostringstream msgbuf; diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp index 6d97258ec..063fbd6c2 100644 --- a/lib/remote/apilistener-configsync.cpp +++ b/lib/remote/apilistener-configsync.cpp @@ -133,7 +133,7 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin << "Could not create object '" << objName << "':"; ObjectLock olock(errors); - for (const String& error : errors) { + for (auto& error : errors) { Log(LogCritical, "ApiListener", error); } @@ -300,7 +300,7 @@ Value ApiListener::ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin Log(LogCritical, "ApiListener", "Could not delete object:"); ObjectLock olock(errors); - for (const String& error : errors) { + for (auto& error : errors) { Log(LogCritical, "ApiListener", error); } } diff --git a/lib/remote/consolehandler.cpp b/lib/remote/consolehandler.cpp index f5a470a9a..8ed36311c 100644 --- a/lib/remote/consolehandler.cpp +++ b/lib/remote/consolehandler.cpp @@ -32,9 +32,7 @@ static void ScriptFrameCleanupHandler() std::vector cleanup_keys; - typedef std::pair KVPair; - - for (const KVPair& kv : l_ApiScriptFrames) { + for (auto& kv : l_ApiScriptFrames) { if (kv.second.Seen < Utility::GetTime() - 1800) cleanup_keys.push_back(kv.first); } diff --git a/lib/remote/eventqueue.cpp b/lib/remote/eventqueue.cpp index 4705d4050..819f95a6a 100644 --- a/lib/remote/eventqueue.cpp +++ b/lib/remote/eventqueue.cpp @@ -44,8 +44,7 @@ void EventQueue::ProcessEvent(const Dictionary::Ptr& event) std::unique_lock lock(m_Mutex); - typedef std::pair > kv_pair; - for (kv_pair& kv : m_Events) { + for (auto& kv : m_Events) { kv.second.push_back(event); } @@ -108,8 +107,7 @@ std::vector EventQueue::GetQueuesForType(const String& type) std::vector availQueues; - typedef std::pair kv_pair; - for (const kv_pair& kv : queues) { + for (auto& kv : queues) { if (kv.second->CanProcessEvent(type)) availQueues.push_back(kv.second); } diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 693011369..755922816 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -902,7 +902,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) if (field.Type.ArrayRank > 0) { m_Impl << "\t" << "if (oldValue) {" << std::endl << "\t\t" << "ObjectLock olock(oldValue);" << std::endl - << "\t\t" << "for (const String& ref : oldValue) {" << std::endl + << "\t\t" << "for (auto& ref : oldValue) {" << std::endl << "\t\t\tDependencyGraph::RemoveDependency("; /* Ew */ @@ -916,7 +916,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) << "\t" << "}" << std::endl << "\t" << "if (newValue) {" << std::endl << "\t\t" << "ObjectLock olock(newValue);" << std::endl - << "\t\t" << "for (const String& ref : newValue) {" << std::endl + << "\t\t" << "for (auto& ref : newValue) {" << std::endl << "\t\t\tDependencyGraph::AddDependency("; /* Ew */