From 832f67e91c8b01614a1e08e4e7039e82d541af5d Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 10 Jul 2025 21:28:54 -0700 Subject: [PATCH 1/2] Disable a few new modernize clang-tidy checkers, enabled by C++20 --- .clang-tidy | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index f4b83da5f5..9bc2fc61ac 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -16,6 +16,7 @@ Checks: [-*, -bugprone-unchecked-optional-access, -performance-unnecessary-value-param, -modernize-use-equals-default, + -modernize-use-integer-sign-comparison, # The following cause either lots of pointless or advisory warnings -bugprone-easily-swappable-parameters, @@ -43,6 +44,7 @@ Checks: [-*, -modernize-use-nodiscard, -modernize-use-ranges, -modernize-use-trailing-return-type, + -modernize-use-designated-initializers, # This one returns a bunch of findings in DFA and the sqlite library. # We're unlikely to fix either of them. @@ -64,6 +66,10 @@ Checks: [-*, -modernize-use-std-format, -modernize-use-std-numbers, -modernize-use-std-print, + + # C++20 supports constraints but until Spicy supports building with C++20 + # this one has to stay disabled. + -modernize-use-constraints, ] HeaderFilterRegex: '.h' From 8640f92b1fb48d0ed7be7f6a6d648aadf5e81750 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 10 Jul 2025 21:32:18 -0700 Subject: [PATCH 2/2] Use ranges::reverse_view to fix a few reverse ranged-for loops --- src/Func.cc | 7 +++---- src/Scope.cc | 6 ++++-- src/plugin/Manager.cc | 5 +++-- src/spicy/runtime-support.cc | 7 ++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Func.cc b/src/Func.cc index 6f44bd6b6b..b7ac9a0d70 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -15,6 +15,7 @@ #include #include #include +#include // Most of these includes are needed for code included from bif files. #include "zeek/Base64.h" @@ -88,11 +89,10 @@ std::string render_call_stack() { if ( ! detail::call_stack.empty() ) rval += "| "; - for ( auto it = detail::call_stack.rbegin(); it != detail::call_stack.rend(); ++it ) { + for ( auto& ci : std::ranges::reverse_view(detail::call_stack) ) { if ( lvl > 0 ) rval += " | "; - auto& ci = *it; const auto& name = ci.func->GetName(); std::string arg_desc; @@ -938,8 +938,7 @@ zeek::VectorValPtr get_current_script_backtrace() { // to prevent problems with iterator invalidation. auto cs_copy = zeek::detail::call_stack; - for ( auto it = cs_copy.rbegin(); it != cs_copy.rend(); ++it ) { - const auto& ci = *it; + for ( const auto& ci : std::ranges::reverse_view(cs_copy) ) { if ( ! ci.func ) // This happens for compiled code. continue; diff --git a/src/Scope.cc b/src/Scope.cc index 6be15e9cb6..b97dbe77d2 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -2,6 +2,8 @@ #include "zeek/Scope.h" +#include + #include "zeek/Desc.h" #include "zeek/ID.h" #include "zeek/IntrusivePtr.h" @@ -112,8 +114,8 @@ const IDPtr& lookup_ID(const char* name, const char* curr_module, bool no_global if ( ! explicit_global ) { bool need_export = check_export && (ID_module != GLOBAL_MODULE_NAME && ID_module != curr_module); - for ( auto s_i = scopes.rbegin(); s_i != scopes.rend(); ++s_i ) { - const auto& id = (*s_i)->Find(fullname); + for ( const auto& s_i : std::ranges::reverse_view(scopes) ) { + const auto& id = s_i->Find(fullname); if ( id ) { if ( need_export && ! id->IsExport() && ! in_debug ) diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index a718295fa9..36f68862f1 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -375,8 +376,8 @@ void Manager::ActivateDynamicPlugins(bool all) { } void Manager::UpdateInputFiles() { - for ( file_list::const_reverse_iterator i = scripts_to_load.rbegin(); i != scripts_to_load.rend(); i++ ) - add_input_file_at_front((*i).c_str()); + for ( const auto& script : std::ranges::reverse_view(scripts_to_load) ) + add_input_file_at_front(script.c_str()); scripts_to_load.clear(); } diff --git a/src/spicy/runtime-support.cc b/src/spicy/runtime-support.cc index 9006ec2389..ba321c9435 100644 --- a/src/spicy/runtime-support.cc +++ b/src/spicy/runtime-support.cc @@ -3,6 +3,7 @@ #include "zeek/spicy/runtime-support.h" #include +#include #include #include @@ -886,9 +887,9 @@ const rt::cookie::FileState* rt::cookie::FileStateStack::find(const std::string& auto _ = hilti::rt::profiler::start("zeek/rt/file-stack-find"); // Reverse search as the default state would be on top of the stack. - for ( auto i = _stack.rbegin(); i != _stack.rend(); i++ ) { - if ( i->fid == fid ) - return &*i; + for ( const auto& i : std::ranges::reverse_view(_stack) ) { + if ( i.fid == fid ) + return &i; } return nullptr;