Merge remote-tracking branch 'origin/topic/timw/cpp20-clang-tidy-updates'

* origin/topic/timw/cpp20-clang-tidy-updates:
  Use ranges::reverse_view to fix a few reverse ranged-for loops
  Disable a few new modernize clang-tidy checkers, enabled by C++20
This commit is contained in:
Tim Wojtulewicz 2025-07-14 09:31:19 -07:00
commit a843521e78
7 changed files with 31 additions and 12 deletions

View file

@ -16,6 +16,7 @@ Checks: [-*,
-bugprone-unchecked-optional-access, -bugprone-unchecked-optional-access,
-performance-unnecessary-value-param, -performance-unnecessary-value-param,
-modernize-use-equals-default, -modernize-use-equals-default,
-modernize-use-integer-sign-comparison,
# The following cause either lots of pointless or advisory warnings # The following cause either lots of pointless or advisory warnings
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
@ -43,6 +44,7 @@ Checks: [-*,
-modernize-use-nodiscard, -modernize-use-nodiscard,
-modernize-use-ranges, -modernize-use-ranges,
-modernize-use-trailing-return-type, -modernize-use-trailing-return-type,
-modernize-use-designated-initializers,
# This one returns a bunch of findings in DFA and the sqlite library. # This one returns a bunch of findings in DFA and the sqlite library.
# We're unlikely to fix either of them. # We're unlikely to fix either of them.
@ -64,6 +66,10 @@ Checks: [-*,
-modernize-use-std-format, -modernize-use-std-format,
-modernize-use-std-numbers, -modernize-use-std-numbers,
-modernize-use-std-print, -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' HeaderFilterRegex: '.h'

10
CHANGES
View file

@ -1,3 +1,13 @@
8.0.0-dev.651 | 2025-07-14 09:31:19 -0700
* Use ranges::reverse_view to fix a few reverse ranged-for loops (Tim Wojtulewicz)
* Disable a few new modernize clang-tidy checkers, enabled by C++20 (Tim Wojtulewicz)
* btest: Switch putty.org usage in tests to official URL (Arne Welzel, Corelight)
Closes #4655
8.0.0-dev.646 | 2025-07-13 19:22:52 -0700 8.0.0-dev.646 | 2025-07-13 19:22:52 -0700
* Move util::Deferred into util-types.h (Tim Wojtulewicz, Corelight) * Move util::Deferred into util-types.h (Tim Wojtulewicz, Corelight)

View file

@ -1 +1 @@
8.0.0-dev.646 8.0.0-dev.651

View file

@ -15,6 +15,7 @@
#include <cerrno> #include <cerrno>
#include <csignal> #include <csignal>
#include <cstdlib> #include <cstdlib>
#include <ranges>
// Most of these includes are needed for code included from bif files. // Most of these includes are needed for code included from bif files.
#include "zeek/Base64.h" #include "zeek/Base64.h"
@ -88,11 +89,10 @@ std::string render_call_stack() {
if ( ! detail::call_stack.empty() ) if ( ! detail::call_stack.empty() )
rval += "| "; 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 ) if ( lvl > 0 )
rval += " | "; rval += " | ";
auto& ci = *it;
const auto& name = ci.func->GetName(); const auto& name = ci.func->GetName();
std::string arg_desc; std::string arg_desc;
@ -938,8 +938,7 @@ zeek::VectorValPtr get_current_script_backtrace() {
// to prevent problems with iterator invalidation. // to prevent problems with iterator invalidation.
auto cs_copy = zeek::detail::call_stack; auto cs_copy = zeek::detail::call_stack;
for ( auto it = cs_copy.rbegin(); it != cs_copy.rend(); ++it ) { for ( const auto& ci : std::ranges::reverse_view(cs_copy) ) {
const auto& ci = *it;
if ( ! ci.func ) if ( ! ci.func )
// This happens for compiled code. // This happens for compiled code.
continue; continue;

View file

@ -2,6 +2,8 @@
#include "zeek/Scope.h" #include "zeek/Scope.h"
#include <ranges>
#include "zeek/Desc.h" #include "zeek/Desc.h"
#include "zeek/ID.h" #include "zeek/ID.h"
#include "zeek/IntrusivePtr.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 ) { if ( ! explicit_global ) {
bool need_export = check_export && (ID_module != GLOBAL_MODULE_NAME && ID_module != curr_module); 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 ) { for ( const auto& s_i : std::ranges::reverse_view(scopes) ) {
const auto& id = (*s_i)->Find(fullname); const auto& id = s_i->Find(fullname);
if ( id ) { if ( id ) {
if ( need_export && ! id->IsExport() && ! in_debug ) if ( need_export && ! id->IsExport() && ! in_debug )

View file

@ -12,6 +12,7 @@
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include <optional> #include <optional>
#include <ranges>
#include <regex> #include <regex>
#include <sstream> #include <sstream>
@ -375,8 +376,8 @@ void Manager::ActivateDynamicPlugins(bool all) {
} }
void Manager::UpdateInputFiles() { void Manager::UpdateInputFiles() {
for ( file_list::const_reverse_iterator i = scripts_to_load.rbegin(); i != scripts_to_load.rend(); i++ ) for ( const auto& script : std::ranges::reverse_view(scripts_to_load) )
add_input_file_at_front((*i).c_str()); add_input_file_at_front(script.c_str());
scripts_to_load.clear(); scripts_to_load.clear();
} }

View file

@ -3,6 +3,7 @@
#include "zeek/spicy/runtime-support.h" #include "zeek/spicy/runtime-support.h"
#include <memory> #include <memory>
#include <ranges>
#include <hilti/rt/exception.h> #include <hilti/rt/exception.h>
#include <hilti/rt/profiler.h> #include <hilti/rt/profiler.h>
@ -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"); auto _ = hilti::rt::profiler::start("zeek/rt/file-stack-find");
// Reverse search as the default state would be on top of the stack. // Reverse search as the default state would be on top of the stack.
for ( auto i = _stack.rbegin(); i != _stack.rend(); i++ ) { for ( const auto& i : std::ranges::reverse_view(_stack) ) {
if ( i->fid == fid ) if ( i.fid == fid )
return &*i; return &i;
} }
return nullptr; return nullptr;