Building m4-1.4.21 on CentOS 6, which comes with gcc 4.4.7, produces
this compilation error:

$ ./configure
$ make V=1
...
depbase=`echo format.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        gcc -std=gnu99    -I../lib -I../lib    -g -O2 -MT format.o -MD -MP -MF 
$depbase.Tpo -c -o format.o format.c &&\
        mv -f $depbase.Tpo $depbase.Po
format.c: In function 'expand_format':
format.c:355: error: #pragma GCC diagnostic not allowed inside functions
format.c:356: error: #pragma GCC diagnostic not allowed inside functions
format.c:385: error: #pragma GCC diagnostic not allowed inside functions
make[2]: *** [format.o] Error 1

gcc versions 4.3, 4.4, 4.5 don't accept '#pragma GCC diagnostic' inside
functions. Only gcc versions >= 4.6 and clang do.

Find attached a proposed fix.

>From ecbfd1c72e43514430298770954f0d70ebf485c5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 20 Sep 2026 01:55:18 +0200
Subject: [PATCH] maint: Fix compilation error with gcc 4.3, 4.4, 4.5
 (regression 2025-04-04).

* src/format.c (expand_format): Don't use '# pragma GCC diagnostic' inside
a function for gcc versions < 4.6.
---
 src/format.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/format.c b/src/format.c
index 4057d375..cc59a355 100644
--- a/src/format.c
+++ b/src/format.c
@@ -331,7 +331,7 @@ expand_format (struct obstack *obs, idx_t argc, token_data **argv)
         }
 
       /* Our constructed format string in fstart is safe.  */
-#if _GL_GNUC_PREREQ (4, 3) || defined __clang__
+#if _GL_GNUC_PREREQ (4, 6) || defined __clang__
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
@@ -395,7 +395,7 @@ expand_format (struct obstack *obs, idx_t argc, token_data **argv)
         default:
           abort ();
         }
-#if _GL_GNUC_PREREQ (4, 3) || defined __clang__
+#if _GL_GNUC_PREREQ (4, 6) || defined __clang__
 # pragma GCC diagnostic pop
 #endif
 
-- 
2.53.0

  • compilation er... Bruno Haible via Bug reports for the GNU m4 macro processor

Reply via email to