A new clang-tidy has introduce some new warnings. David Gibson (2): conf: Fix clang-tidy warning about using an undefined enum value clang-tidy: Suppress macro to enum conversion warnings Makefile | 9 ++++++++- conf.c | 4 ++-- fwd.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) -- 2.45.0
In conf() we temporarily set the forwarding mode variables to 0 - an invalid value, so that we can check later if they've been set by the intervening logic. clang-tidy 18.1.1 in Fedora 40 now complains about this. Satisfy it by giving an name in the enum to the 0 value. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- conf.c | 4 ++-- fwd.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/conf.c b/conf.c index 3f30725..21d46fe 100644 --- a/conf.c +++ b/conf.c @@ -1203,8 +1203,8 @@ void conf(struct ctx *c, int argc, char **argv) optstring = "dqfel:hs:F:p:P:m:a:n:M:g:i:o:D:S:461t:u:"; } - c->tcp.fwd_in.mode = c->tcp.fwd_out.mode = 0; - c->udp.fwd_in.f.mode = c->udp.fwd_out.f.mode = 0; + c->tcp.fwd_in.mode = c->tcp.fwd_out.mode = FWD_UNSET; + c->udp.fwd_in.f.mode = c->udp.fwd_out.f.mode = FWD_UNSET; do { name = getopt_long(argc, argv, optstring, options, NULL); diff --git a/fwd.h b/fwd.h index 23281d9..41645d7 100644 --- a/fwd.h +++ b/fwd.h @@ -11,6 +11,7 @@ #define NUM_PORTS (1U << 16) enum fwd_ports_mode { + FWD_UNSET = 0, FWD_SPEC = 1, FWD_NONE, FWD_AUTO, -- 2.45.0
clang-tidy 18.1.1 in Fedora 40 complains about every #define of an integral value, suggesting it be converted to an enum. Although that's certainly possible, it's of dubious value and results in some awkward arrangements on out codebase. Suppress it globally. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c1e1f06..8ea1757 100644 --- a/Makefile +++ b/Makefile @@ -257,6 +257,12 @@ docs: README.md # we use. That sounds nice, but means it will often want a OS # specific header instead of a mostly standard one, such as # <linux/limits.h> instead of <limits.h>. +# +# - cppcoreguidelines-macro-to-enum +# Want to replace all #defines of integers with enums. Kind of +# makes sense when those defines form an enum-like set, but +# weird for cases like standalone constants, and causes other +# awkwardness for a bunch of cases we use clang-tidy: $(SRCS) $(HEADERS) clang-tidy -checks=*,-modernize-*,\ @@ -283,7 +289,8 @@ clang-tidy: $(SRCS) $(HEADERS) -altera-struct-pack-align,\ -concurrency-mt-unsafe,\ -readability-identifier-length,\ - -misc-include-cleaner \ + -misc-include-cleaner,\ + -cppcoreguidelines-macro-to-enum \ -config='{CheckOptions: [{key: bugprone-suspicious-string-compare.WarnOnImplicitComparison, value: "false"}]}' \ --warnings-as-errors=* $(SRCS) -- $(filter-out -pie,$(FLAGS) $(CFLAGS) $(CPPFLAGS)) -DCLANG_TIDY_58992 -- 2.45.0
On Tue, 14 May 2024 00:57:58 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:clang-tidy 18.1.1 in Fedora 40 complains about every #define of an integral value, suggesting it be converted to an enum.Oh, wow, that's a bit heavy-handed. Series applied. -- Stefano