On 2026-01-19 06:22, Pádraig Brady wrote:
+/* Suppress GCC's -Wsuggest-attribute=pure + incorrectly generated by GCC versions up to at least GCC 15.1. + Note with attribute pure, `clang -fno-inline` would eliminate + calls to check_nonnull(). */ +#if _GL_GNUC_PREREQ (4, 7) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" +#endif
Ouch, and thanks for catching this.A couple of things. First, in other places Gnulib does this, it checks for GCC 4.6 not 4.7, and omits the push/pop presumably because inlining might cause GCC to emit the warning anyway for later functions. Second, it's probably best not to make promises about clang since none of that stuff is guaranteed. Oh, and the problem also occurs in GCC 15.2. So I installed the attached minor followup.
From e3d5c5d79e28779c8d42c729d39d72403b7ae162 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Mon, 19 Jan 2026 09:33:36 -0800 Subject: [PATCH] xalloc: tweak for GCC 4.6, possible inlining bugs * lib/xmalloc.c: Also ignore -Wsuggest-attribute=pure for GCC 4.6, and do not pop the warning. This is consistent with how gnulib does this sort of thing elsewhere. --- ChangeLog | 7 +++++++ lib/xmalloc.c | 13 ++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27f0a53803..b96ea8fcf3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2026-01-19 Paul Eggert <[email protected]> + + xalloc: tweak for GCC 4.6, possible inlining bugs + * lib/xmalloc.c: Also ignore -Wsuggest-attribute=pure for GCC 4.6, + and do not pop the warning. This is consistent with how gnulib + does this sort of thing elsewhere. + 2026-01-19 Pádraig Brady <[email protected]> xalloc: use check_nonnull() in more places diff --git a/lib/xmalloc.c b/lib/xmalloc.c index f00ea5e7a4..545beb353a 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -27,14 +27,12 @@ #include <stdint.h> #include <string.h> -/* Suppress GCC's -Wsuggest-attribute=pure - incorrectly generated by GCC versions up to at least GCC 15.1. - Note with attribute pure, `clang -fno-inline` would eliminate - calls to check_nonnull(). */ -#if _GL_GNUC_PREREQ (4, 7) -# pragma GCC diagnostic push +/* Pacify GCC up to at least 15.2, which otherwise would incorrectly + complain about check_nonnull. */ +#if _GL_GNUC_PREREQ (4, 6) # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" #endif + static void * check_nonnull (void *p) { @@ -42,9 +40,6 @@ check_nonnull (void *p) xalloc_die (); return p; } -#if _GL_GNUC_PREREQ (4, 7) -# pragma GCC diagnostic pop -#endif /* Allocate S bytes of memory dynamically, with error checking. */ -- 2.51.0
