]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Avoid trailing whitespace in config.h
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Jan 2026 20:41:00 +0000 (12:41 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Jan 2026 20:42:12 +0000 (12:42 -0800)
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
lib/autoconf/status.m4
tests/torture.at

diff --git a/NEWS b/NEWS
index 3ebeabaef49fbf936a6f5d4df91de92c18fbc36e..da40e8a4505478351b94518a68653efce666aac6 100644 (file)
--- 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
index 3836a453c31dca00d820c78bd147513c354fd518..472c1e6cdb424e49acc1d2ecfef0edf87942f336 100644 (file)
@@ -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,
index 3b1d9f082c748f4624702bc5ae77419892415138..0332a08f79d97f69666622dead7c4f8a5f8be201 100644 (file)
@@ -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.  ##