From 62c1745f627bb109e45c64ae510f5029df051da4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Jan 2024 10:56:54 +0100 Subject: [PATCH] std-aux: suppress "-Wnonnull-compare" warning in nm_assert() When we use a "static" array declarator to a function, we understand and tell the compiler that the argument must not be NULL. But now gcc-14.0.1-0.2.fc40 starts warning about NULL checks for such arguments. static void foo(char args[static 10]) { nm_assert(args); sprintf(args, "hi"); } Granted, the compiler is right, and we know that this condition is not supposed to be violated. A logical thing would be just to drop the assertion. Instead, suppress "-Wnonnull-compare" warnings inside a nm_assert(). An nm_assert() is more than a run time check, it's an additional self-documenting code of the invariants. It's fine to assert for something that is true. Actually, all the conditions that we assert against, hold. The compiler telling us that the condition that we assert against is valid, is not useful. --- src/libnm-std-aux/nm-std-aux.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index a1e89680b6..2575be4b69 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -288,6 +288,8 @@ typedef uint64_t _nm_bitwise nm_be64_t; #define nm_assert(cond) \ ({ \ + NM_PRAGMA_WARNING_DISABLE("-Wnonnull-compare"); \ + \ /* nm_assert() must do *nothing* of effect, except evaluating * @cond (0 or 1 times). * @@ -305,6 +307,9 @@ typedef uint64_t _nm_bitwise nm_be64_t; } else { \ _nm_assert_fail(#cond); \ } \ + \ + NM_PRAGMA_WARNING_REENABLE; \ + \ 1; \ })