diff --git a/CMakeLists.txt b/CMakeLists.txt index fce41f411..86abc77d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,7 +237,7 @@ endif() set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winconsistent-missing-override") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winconsistent-missing-override -Wrange-loop-construct") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics -fno-limit-debug-info") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics -fno-limit-debug-info") @@ -258,6 +258,10 @@ endif() if(CMAKE_C_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override") + if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL "11.0.0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-construct") + endif() + if(CMAKE_SYSTEM_NAME MATCHES AIX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -lpthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -lpthread") diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 1811c8e07..d4e27c566 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -401,7 +401,7 @@ static int Main() #endif /* _WIN32 */ if (vm.count("define")) { - for (const String& define : vm["define"].as >()) { + for (String define : vm["define"].as>()) { String key, value; size_t pos = define.FindFirstOf('='); if (pos != String::NPos) { @@ -460,7 +460,7 @@ static int Main() ConfigCompiler::AddIncludeSearchDir(Configuration::IncludeConfDir); if (!autocomplete && vm.count("include")) { - for (const String& includePath : vm["include"].as >()) { + for (String includePath : vm["include"].as>()) { ConfigCompiler::AddIncludeSearchDir(includePath); } } 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/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 3611799ff..9054dadd6 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -124,7 +124,7 @@ bool ScriptUtils::Regex(const std::vector& args) if (texts->GetLength() == 0) return false; - for (const String& text : texts) { + for (String text : texts) { bool res = false; try { boost::smatch what; @@ -177,7 +177,7 @@ bool ScriptUtils::Match(const std::vector& args) if (texts->GetLength() == 0) return false; - for (const String& text : texts) { + for (String text : texts) { bool res = Utility::Match(pattern, text); if (mode == MatchAny && res) @@ -223,7 +223,7 @@ bool ScriptUtils::CidrMatch(const std::vector& args) if (ips->GetLength() == 0) return false; - for (const String& ip : ips) { + for (String ip : ips) { bool res = Utility::CidrMatch(pattern, ip); if (mode == MatchAny && res) diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp index 5e250d22c..3116f8ca4 100644 --- a/lib/cli/daemonutility.cpp +++ b/lib/cli/daemonutility.cpp @@ -121,7 +121,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector& configs, ConfigCompilerContext::GetInstance()->OpenObjectsFile(objectsFile); if (!configs.empty()) { - for (const String& configPath : configs) { + for (String configPath : configs) { try { std::unique_ptr expression = ConfigCompiler::CompileFile(configPath, String(), "_etc"); success = ExecuteExpression(&*expression); 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/cli/nodeutility.cpp b/lib/cli/nodeutility.cpp index 523532a24..e2986c3ee 100644 --- a/lib/cli/nodeutility.cpp +++ b/lib/cli/nodeutility.cpp @@ -47,7 +47,7 @@ int NodeUtility::GenerateNodeIcingaConfig(const String& endpointName, const Stri Array::Ptr myParentZoneMembers = new Array(); - for (const String& endpoint : endpoints) { + for (String endpoint : endpoints) { /* extract all --endpoint arguments and store host,port info */ std::vector tokens = endpoint.Split(","); @@ -170,7 +170,7 @@ bool NodeUtility::WriteNodeConfigObjects(const String& filename, const Array::Pt fp << " */\n\n"; ObjectLock olock(objects); - for (const Dictionary::Ptr& object : objects) { + for (Dictionary::Ptr object : objects) { SerializeObject(fp, object); } diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index 3a3cd42bd..c6874a5af 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -242,7 +242,7 @@ wizard_endpoint_loop_start: /* Extract parent node information. */ String parentHost, parentPort; - for (const String& endpoint : endpoints) { + for (String endpoint : endpoints) { std::vector tokens = endpoint.Split(","); if (tokens.size() > 1) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 627b9b74e..3f38683b6 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -161,7 +161,7 @@ void HostDbObject::OnConfigUpdateHeavy() if (groups) { ObjectLock olock(groups); - for (const String& groupName : groups) { + for (String groupName : groups) { HostGroup::Ptr group = HostGroup::GetByName(groupName); DbQuery query2; diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 6d0701111..b221845a8 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -159,7 +159,7 @@ void ServiceDbObject::OnConfigUpdateHeavy() if (groups) { ObjectLock olock(groups); - for (const String& groupName : groups) { + for (String groupName : groups) { ServiceGroup::Ptr group = ServiceGroup::GetByName(groupName); DbQuery query2; diff --git a/lib/db_ido/userdbobject.cpp b/lib/db_ido/userdbobject.cpp index 439b8fb05..74c1284b0 100644 --- a/lib/db_ido/userdbobject.cpp +++ b/lib/db_ido/userdbobject.cpp @@ -79,7 +79,7 @@ void UserDbObject::OnConfigUpdateHeavy() if (groups) { ObjectLock olock(groups); - for (const String& groupName : groups) { + for (String groupName : groups) { UserGroup::Ptr group = UserGroup::GetByName(groupName); DbQuery query2; diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp index b49d2071d..87821dcea 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -1358,7 +1358,7 @@ Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::P { ObjectLock olock(ausers); - for (const String& auser : ausers) { + for (String auser : ausers) { User::Ptr user = User::GetByName(auser); if (!user) diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 846735262..449fe2334 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -169,7 +169,7 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp if (!ConfigObjectUtility::CreateObject(Comment::TypeInstance, fullName, config, errors, nullptr)) { ObjectLock olock(errors); - for (const String& error : errors) { + for (String error : errors) { Log(LogCritical, "Comment", error); } @@ -206,7 +206,7 @@ void Comment::RemoveComment(const String& id, bool removedManually, const String if (!ConfigObjectUtility::DeleteObject(comment, false, errors, nullptr)) { ObjectLock olock(errors); - for (const String& error : errors) { + for (String error : errors) { Log(LogCritical, "Comment", error); } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 95aed4396..a985b90f5 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -25,7 +25,7 @@ String CompatUtility::GetCommandLine(const Command::Ptr& command) Array::Ptr args = commandLine; ObjectLock olock(args); - for (const String& arg : args) { + for (String arg : args) { // This is obviously incorrect for non-trivial cases. result += " \"" + EscapeString(arg) + "\""; } diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 98a65d417..66462cef6 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -330,7 +330,7 @@ Downtime::Ptr Downtime::AddDowntime(const Checkable::Ptr& checkable, const Strin if (!ConfigObjectUtility::CreateObject(Downtime::TypeInstance, fullName, config, errors, nullptr)) { ObjectLock olock(errors); - for (const String& error : errors) { + for (String error : errors) { Log(LogCritical, "Downtime", error); } @@ -388,7 +388,7 @@ void Downtime::RemoveDowntime(const String& id, bool includeChildren, DowntimeRe if (!ConfigObjectUtility::DeleteObject(downtime, false, errors, nullptr)) { ObjectLock olock(errors); - for (const String& error : errors) { + for (String error : errors) { Log(LogCritical, "Downtime", error); } @@ -505,7 +505,7 @@ void Downtime::TriggerDowntime(double triggerTime) { ObjectLock olock(triggers); - for (const String& triggerName : triggers) { + for (String triggerName : triggers) { Downtime::Ptr downtime = Downtime::GetByName(triggerName); if (!downtime) diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 22dd79b40..10cd4b445 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -38,7 +38,7 @@ void Host::OnAllConfigLoaded() ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { HostGroup::Ptr hg = HostGroup::GetByName(name); if (hg) @@ -71,7 +71,7 @@ void Host::Stop(bool runtimeRemoved) if (groups) { ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { HostGroup::Ptr hg = HostGroup::GetByName(name); if (hg) @@ -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/hostgroup.cpp b/lib/icinga/hostgroup.cpp index a22f3b74c..9ab338300 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -91,7 +91,7 @@ bool HostGroup::ResolveGroupMembership(const Host::Ptr& host, bool add, int rsta if (groups && groups->GetLength() > 0) { ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { HostGroup::Ptr group = HostGroup::GetByName(name); if (group && !group->ResolveGroupMembership(host, add, rstack + 1)) diff --git a/lib/icinga/legacytimeperiod.cpp b/lib/icinga/legacytimeperiod.cpp index 6d2433758..adcd85b8c 100644 --- a/lib/icinga/legacytimeperiod.cpp +++ b/lib/icinga/legacytimeperiod.cpp @@ -486,7 +486,7 @@ Dictionary::Ptr LegacyTimePeriod::FindRunningSegment(const String& daydef, const double bestEnd = 0.0; ObjectLock olock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { double begin = segment->Get("begin"); double end = segment->Get("end"); @@ -544,7 +544,7 @@ Dictionary::Ptr LegacyTimePeriod::FindNextSegment(const String& daydef, const St double bestBegin; ObjectLock olock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { double begin = segment->Get("begin"); if (begin < tsref) diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 63e24b746..8c4cced1b 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -173,7 +173,7 @@ std::set Notification::GetUsers() const if (users) { ObjectLock olock(users); - for (const String& name : users) { + for (String name : users) { User::Ptr user = User::GetByName(name); if (!user) @@ -195,7 +195,7 @@ std::set Notification::GetUserGroups() const if (groups) { ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { UserGroup::Ptr ug = UserGroup::GetByName(name); if (!ug) @@ -667,8 +667,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/icinga/service.cpp b/lib/icinga/service.cpp index c24647c82..a26512b77 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -65,7 +65,7 @@ void Service::OnAllConfigLoaded() ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { ServiceGroup::Ptr sg = ServiceGroup::GetByName(name); if (sg) diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index d21f852b9..ee2bc9c6e 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -94,7 +94,7 @@ bool ServiceGroup::ResolveGroupMembership(const Service::Ptr& service, bool add, if (groups && groups->GetLength() > 0) { ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { ServiceGroup::Ptr group = ServiceGroup::GetByName(name); if (group && !group->ResolveGroupMembership(service, add, rstack + 1)) diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index e305b80ad..d5188a68b 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -57,7 +57,7 @@ void TimePeriod::AddSegment(double begin, double end) if (segments) { /* Try to merge the new segment into an existing segment. */ ObjectLock dlock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { if (segment->Get("begin") <= begin && segment->Get("end") >= end) return; /* New segment is fully contained in this segment. */ @@ -122,7 +122,7 @@ void TimePeriod::RemoveSegment(double begin, double end) /* Try to split or adjust an existing segment. */ ObjectLock dlock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { /* Fully contained in the specified range? */ if (segment->Get("begin") >= begin && segment->Get("end") <= end) // Don't add the old segment, because the segment is fully contained into our range @@ -193,7 +193,7 @@ void TimePeriod::PurgeSegments(double end) /* Remove old segments. */ ObjectLock dlock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { if (segment->Get("end") >= end) newSegments->Add(segment); } @@ -212,7 +212,7 @@ void TimePeriod::Merge(const TimePeriod::Ptr& timeperiod, bool include) if (segments) { ObjectLock dlock(segments); ObjectLock ilock(this); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { include ? AddSegment(segment) : RemoveSegment(segment); } } @@ -239,7 +239,7 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting) if (segments) { ObjectLock dlock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { AddSegment(segment); } } @@ -252,7 +252,7 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting) if (timeranges) { ObjectLock olock(timeranges); - for (const String& name : timeranges) { + for (String name : timeranges) { const TimePeriod::Ptr timeperiod = TimePeriod::GetByName(name); if (timeperiod) @@ -265,7 +265,7 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting) if (timeranges) { ObjectLock olock(timeranges); - for (const String& name : timeranges) { + for (String name : timeranges) { const TimePeriod::Ptr timeperiod = TimePeriod::GetByName(name); if (timeperiod) @@ -290,7 +290,7 @@ bool TimePeriod::IsInside(double ts) const if (segments) { ObjectLock dlock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { if (ts >= segment->Get("begin") && ts < segment->Get("end")) return true; } @@ -309,7 +309,7 @@ double TimePeriod::FindNextTransition(double begin) if (segments) { ObjectLock dlock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { if (segment->Get("begin") > begin && (segment->Get("begin") < closestTransition || closestTransition == -1)) closestTransition = segment->Get("begin"); @@ -360,7 +360,7 @@ void TimePeriod::Dump() if (segments) { ObjectLock dlock(segments); - for (const Dictionary::Ptr& segment : segments) { + for (Dictionary::Ptr segment : segments) { Log(LogDebug, "TimePeriod") << "Segment: " << Utility::FormatDateTime("%c", segment->Get("begin")) << " <-> " << Utility::FormatDateTime("%c", segment->Get("end")); diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 4d99db7a1..5c646f656 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -33,7 +33,7 @@ void User::OnAllConfigLoaded() ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { UserGroup::Ptr ug = UserGroup::GetByName(name); if (ug) @@ -51,7 +51,7 @@ void User::Stop(bool runtimeRemoved) if (groups) { ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { UserGroup::Ptr ug = UserGroup::GetByName(name); if (ug) diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index 1ae89af88..043d2bc8d 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -110,7 +110,7 @@ bool UserGroup::ResolveGroupMembership(const User::Ptr& user, bool add, int rsta if (groups && groups->GetLength() > 0) { ObjectLock olock(groups); - for (const String& name : groups) { + for (String name : groups) { UserGroup::Ptr group = UserGroup::GetByName(name); if (group && !group->ResolveGroupMembership(user, add, rstack + 1)) diff --git a/lib/livestatus/attributefilter.cpp b/lib/livestatus/attributefilter.cpp index 50d7244eb..a27c7d7af 100644 --- a/lib/livestatus/attributefilter.cpp +++ b/lib/livestatus/attributefilter.cpp @@ -27,7 +27,7 @@ bool AttributeFilter::Apply(const Table::Ptr& table, const Value& row) bool negate = (m_Operator == "<"); ObjectLock olock(array); - for (const String& item : array) { + for (String item : array) { if (item == m_Operand) return !negate; /* Item found in list. */ } 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/livestatus/statehisttable.cpp b/lib/livestatus/statehisttable.cpp index 2d7e49be4..46a6675bb 100644 --- a/lib/livestatus/statehisttable.cpp +++ b/lib/livestatus/statehisttable.cpp @@ -252,7 +252,7 @@ void StateHistTable::FetchRows(const AddRowFunction& addRowFn) Checkable::Ptr checkable; for (const auto& kv : m_CheckablesCache) { - for (const Dictionary::Ptr& state_hist_bag : kv.second) { + for (Dictionary::Ptr state_hist_bag : kv.second) { /* pass a dictionary from state history array */ if (!addRowFn(state_hist_bag, 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/actionshandler.cpp b/lib/remote/actionshandler.cpp index 016c76d57..cd16c2bc0 100644 --- a/lib/remote/actionshandler.cpp +++ b/lib/remote/actionshandler.cpp @@ -88,7 +88,7 @@ bool ActionsHandler::HandleRequest( if (params) verbose = HttpUtility::GetLastParameter(params, "verbose"); - for (const ConfigObject::Ptr& obj : objs) { + for (ConfigObject::Ptr obj : objs) { try { results.emplace_back(action->Invoke(obj, params)); } catch (const std::exception& ex) { @@ -108,7 +108,7 @@ bool ActionsHandler::HandleRequest( int statusCode = 500; std::set okStatusCodes, nonOkStatusCodes; - for (const Dictionary::Ptr& res : results) { + for (Dictionary::Ptr res : results) { if (!res->Contains("code")) { continue; } 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/deleteobjecthandler.cpp b/lib/remote/deleteobjecthandler.cpp index 6a7d194d4..150de99e0 100644 --- a/lib/remote/deleteobjecthandler.cpp +++ b/lib/remote/deleteobjecthandler.cpp @@ -78,7 +78,7 @@ bool DeleteObjectHandler::HandleRequest( bool success = true; - for (const ConfigObject::Ptr& obj : objs) { + for (ConfigObject::Ptr obj : objs) { int code; String status; Array::Ptr errors = new Array(); 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/lib/remote/eventshandler.cpp b/lib/remote/eventshandler.cpp index bdda71461..897398d4a 100644 --- a/lib/remote/eventshandler.cpp +++ b/lib/remote/eventshandler.cpp @@ -73,7 +73,7 @@ bool EventsHandler::HandleRequest( { ObjectLock olock(types); - for (const String& type : types) { + for (String type : types) { FilterUtility::CheckPermission(user, "events/" + type); } } @@ -89,7 +89,7 @@ bool EventsHandler::HandleRequest( { ObjectLock olock(types); - for (const String& type : types) { + for (String type : types) { auto typeId (l_EventTypes.find(type)); if (typeId != l_EventTypes.end()) { diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index d5dc2b6ba..788a97b2e 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -241,7 +241,7 @@ std::vector FilterUtility::GetFilterTargets(const QueryDescription& qd, c Array::Ptr names = query->Get(attr); if (names) { ObjectLock olock(names); - for (const String& name : names) { + for (String name : names) { Object::Ptr target = provider->GetTargetByName(type, name); if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter.get(), target, variableName)) diff --git a/lib/remote/httphandler.cpp b/lib/remote/httphandler.cpp index 71a89e4ce..f67df4c69 100644 --- a/lib/remote/httphandler.cpp +++ b/lib/remote/httphandler.cpp @@ -66,7 +66,7 @@ void HttpHandler::ProcessRequest( if (current_handlers) { ObjectLock olock(current_handlers); - for (const HttpHandler::Ptr& current_handler : current_handlers) { + for (HttpHandler::Ptr current_handler : current_handlers) { handlers.push_back(current_handler); } } diff --git a/lib/remote/modifyobjecthandler.cpp b/lib/remote/modifyobjecthandler.cpp index a817faad8..dabe69523 100644 --- a/lib/remote/modifyobjecthandler.cpp +++ b/lib/remote/modifyobjecthandler.cpp @@ -104,7 +104,7 @@ bool ModifyObjectHandler::HandleRequest( ArrayData results; - for (const ConfigObject::Ptr& obj : objs) { + for (ConfigObject::Ptr obj : objs) { Dictionary::Ptr result1 = new Dictionary(); result1->Set("type", type->GetName()); diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp index 06d168b8a..fbd5c7e70 100644 --- a/lib/remote/objectqueryhandler.cpp +++ b/lib/remote/objectqueryhandler.cpp @@ -23,7 +23,7 @@ Dictionary::Ptr ObjectQueryHandler::SerializeObjectAttrs(const Object::Ptr& obje if (isJoin && attrs) { ObjectLock olock(attrs); - for (const String& attr : attrs) { + for (String attr : attrs) { if (attr == attrPrefix) { allAttrs = true; break; @@ -40,7 +40,7 @@ Dictionary::Ptr ObjectQueryHandler::SerializeObjectAttrs(const Object::Ptr& obje } } else if (attrs) { ObjectLock olock(attrs); - for (const String& attr : attrs) { + for (String attr : attrs) { String userAttr; if (isJoin) { @@ -173,7 +173,7 @@ bool ObjectQueryHandler::HandleRequest( if (ujoins) { ObjectLock olock(ujoins); - for (const String& ujoin : ujoins) { + for (String ujoin : ujoins) { userJoinAttrs.insert(ujoin.SubStr(0, ujoin.FindFirstOf("."))); } } @@ -193,7 +193,7 @@ bool ObjectQueryHandler::HandleRequest( std::unordered_map>> typePermissions; std::unordered_map objectAccessAllowed; - for (const ConfigObject::Ptr& obj : objs) { + for (ConfigObject::Ptr obj : objs) { DictionaryData result1{ { "name", obj->GetName() }, { "type", obj->GetReflectionType()->GetName() } @@ -203,7 +203,7 @@ bool ObjectQueryHandler::HandleRequest( if (umetas) { ObjectLock olock(umetas); - for (const String& meta : umetas) { + for (String meta : umetas) { if (meta == "used_by") { Array::Ptr used_by = new Array(); metaAttrs.emplace_back("used_by", used_by); diff --git a/lib/remote/typequeryhandler.cpp b/lib/remote/typequeryhandler.cpp index 4e8265398..b30dbb14a 100644 --- a/lib/remote/typequeryhandler.cpp +++ b/lib/remote/typequeryhandler.cpp @@ -91,7 +91,7 @@ bool TypeQueryHandler::HandleRequest( ArrayData results; - for (const Type::Ptr& obj : objs) { + for (Type::Ptr obj : objs) { Dictionary::Ptr result1 = new Dictionary(); results.push_back(result1); diff --git a/lib/remote/url.cpp b/lib/remote/url.cpp index bf5b9ed24..24a573184 100644 --- a/lib/remote/url.cpp +++ b/lib/remote/url.cpp @@ -290,7 +290,7 @@ bool Url::ParsePath(const String& path) boost::char_separator sep("/"); boost::tokenizer > tokens(pathStr, sep); - for (const String& token : tokens) { + for (String token : tokens) { if (token.IsEmpty()) continue; @@ -310,7 +310,7 @@ bool Url::ParseQuery(const String& query) boost::char_separator sep("&"); boost::tokenizer > tokens(queryStr, sep); - for (const String& token : tokens) { + for (String token : tokens) { size_t pHelper = token.Find("="); if (pHelper == 0) diff --git a/lib/remote/variablequeryhandler.cpp b/lib/remote/variablequeryhandler.cpp index f17a9f5f2..7264338cb 100644 --- a/lib/remote/variablequeryhandler.cpp +++ b/lib/remote/variablequeryhandler.cpp @@ -98,7 +98,7 @@ bool VariableQueryHandler::HandleRequest( ArrayData results; - for (const Dictionary::Ptr& var : objs) { + for (Dictionary::Ptr var : objs) { if (var->Get("name") == "TicketSalt") continue; diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp index 16e4ba367..95bd1ec8e 100644 --- a/lib/remote/zone.cpp +++ b/lib/remote/zone.cpp @@ -27,7 +27,7 @@ void Zone::OnAllConfigLoaded() if (endpoints) { ObjectLock olock(endpoints); - for (const String& endpoint : endpoints) { + for (String endpoint : endpoints) { Endpoint::Ptr ep = Endpoint::GetByName(endpoint); if (ep) @@ -60,7 +60,7 @@ std::set Zone::GetEndpoints() const if (endpoints) { ObjectLock olock(endpoints); - for (const String& name : endpoints) { + for (String name : endpoints) { Endpoint::Ptr endpoint = Endpoint::GetByName(name); if (!endpoint) diff --git a/plugins/check_nscp_api.cpp b/plugins/check_nscp_api.cpp index aef43fb98..1a4f5571e 100644 --- a/plugins/check_nscp_api.cpp +++ b/plugins/check_nscp_api.cpp @@ -119,7 +119,7 @@ static int FormatOutput(const Dictionary::Ptr& result) ObjectLock olock(perfs); - for (const Dictionary::Ptr& perf : perfs) { + for (Dictionary::Ptr perf : perfs) { ssout << "'" << perf->Get("alias") << "'="; Dictionary::Ptr values = perf->Get("float_value"); @@ -483,7 +483,7 @@ int main(int argc, char **argv) endpoint += '/'; else { endpoint += '?'; - for (const String& argument : vm["arguments"].as>()) { + for (String argument : vm["arguments"].as>()) { String::SizeType pos = argument.FindFirstOf("="); if (pos == String::NPos) endpoint += Utility::EscapeString(argument, ACQUERY_ENCODE, false); diff --git a/test/icinga-legacytimeperiod.cpp b/test/icinga-legacytimeperiod.cpp index 4eb5fb92e..5a32d9570 100644 --- a/test/icinga-legacytimeperiod.cpp +++ b/test/icinga-legacytimeperiod.cpp @@ -502,7 +502,7 @@ BOOST_AUTO_TEST_CASE(dst) std::vector tests; // 2021-03-14: 01:59:59 PST (UTC-8) -> 03:00:00 PDT (UTC-7) - for (const std::string& day : {"2021-03-14", "sunday", "sunday 2", "sunday -3"}) { + for (std::string day : {"2021-03-14", "sunday", "sunday 2", "sunday -3"}) { // range before DST change tests.push_back(TestData{ day, "00:30-01:30", @@ -561,7 +561,7 @@ BOOST_AUTO_TEST_CASE(dst) } // 2021-11-07: 01:59:59 PDT (UTC-7) -> 01:00:00 PST (UTC-8) - for (const std::string& day : {"2021-11-07", "sunday", "sunday 1", "sunday -4"}) { + for (std::string day : {"2021-11-07", "sunday", "sunday 1", "sunday -4"}) { // range before DST change tests.push_back(TestData{ day, "00:15-00:45", 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 */