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.
This commit is contained in:
Thomas Haller 2024-01-23 10:56:54 +01:00 committed by Beniamino Galvani
parent c0338526f3
commit 62c1745f62

View file

@ -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; \
})