On 2026-01-27 11:21, Collin Funk wrote:
[1] https://lists.gnu.org/archive/html/autoconf-patches/2025-10/msg00002.html
Thanks for reminding us. My intuition is that it's better to pacify
-Wtrailing-whitespace by removing the trailing whitespace, instead of
appending " /**/", so I installed the attached instead.
The only place where removing trailing white space is arguably wrong is
a line like "#define ABC \ ", which is so deliberately tricky (and some
C compilers, as I vaguely recall, trim that trailing whitespace anyway,
and the C standard allows this!) that we probably shouldn't support it
anyway.From 32aea018e70f1beca8c07c480e4c2596d1f5c8df Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Tue, 27 Jan 2026 12:41:00 -0800
Subject: [PATCH] Avoid trailing whitespace in config.h
Problem (and earlier patch) reported by Collin Funk in:
https://lists.gnu.org/archive/html/autoconf-patches/2025-10/msg00002.html
* NEWS: Mention this.
* lib/autoconf/status.m4 (_AC_OUTPUT_HEADERS_PREPARE):
Omit trailing white space from C macro definitions.
* tests/torture.at (No trailing white space in macro definitions):
New test.
---
NEWS | 3 +++
lib/autoconf/status.m4 | 6 +++++-
tests/torture.at | 45 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 3ebeabae..da40e8a4 100644
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,9 @@ GNU Autoconf NEWS - User visible changes.
*** AC_DEFINE_UNQUOTED no longer mishandles double-quotes inside $(...)
and ${...}.
+*** AC_DEFINE and similar macros no longer emit trailing whitespace.
+ This pacifies the -Wtrailing-whitespace introduced in GCC 15.
+
*** AC_FUNC_STRNLEN now detects Android 5.0's broken strnlen.
*** AC_PROG_OBJC now finds the GNU Objective-C compiler, as packaged in
diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index 3836a453..472c1e6c 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -838,8 +838,12 @@ cat >>"$CONFIG_STATUS" <<_ACEOF || ac_write_fail=1
macro = mac2[1]
prefix = substr(line, 1, index(line, defundef) - 1)
if (D_is_set[macro]) {
+ suffix = P[macro] D[macro]
+ while (suffix ~ /[\t ]$/) {
+ suffix = substr(suffix, 1, length(suffix) - 1)
+ }
# Preserve the white space surrounding the "#".
- print prefix "define", macro P[macro] D[macro]
+ print prefix "define", macro suffix
next
} else {
# Replace #undef with comments. This is necessary, for example,
diff --git a/tests/torture.at b/tests/torture.at
index 3b1d9f08..0332a08f 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -1029,6 +1029,51 @@ X@file@
done
AT_CLEANUP
+## ---------------------------------------------- ##
+## No trailing white space in macro definitions. ##
+## ---------------------------------------------- ##
+AT_SETUP([No trailing white space in macro definitions])
+AT_KEYWORDS([AC@&t@_DEFINE AC@&t@_DEFINE_UNQUOTED])
+
+AT_DATA([config.hin], [
+#undef EMPTY
+#undef SPACE
+#undef TAB
+#undef LEADING_SPACES
+#undef LEADING_TABS
+])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_HEADERS([config.h:config.hin])
+empty=
+space=' '
+tab=' '
+leading_spaces=' a'
+leading_tabs=' a'
+AC_DEFINE_UNQUOTED([EMPTY], [$empty], [empty])
+AC_DEFINE_UNQUOTED([SPACE], [$space], [space])
+AC_DEFINE_UNQUOTED([TAB], [$tab], [tab])
+AC_DEFINE_UNQUOTED([LEADING_SPACES], [$leading_spaces], [leading spaces])
+AC_DEFINE_UNQUOTED([LEADING_TABS], [$leading_tabs], [leading tabs])
+AC_OUTPUT
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+
+AT_DATA([expout],
+[[/* config.h. Generated from config.hin by configure. */
+
+#define EMPTY
+#define SPACE
+#define TAB
+#define LEADING_SPACES a
+#define LEADING_TABS a
+]])
+AT_CHECK([cat config.h], 0, expout)
+
+AT_CLEANUP
## ---------------------- ##
## Substitute a newline. ##
--
2.51.0