"Zack Weinberg" <[email protected]> writes: > On Sat, Oct 4, 2025, at 2:03 AM, Collin Funk wrote: >> This patch changes config.status to write the following in config.h: >> >> #define TRAILING_WHITESPACE /**/ >> >> When the following lines are in configure.ac: >> >> trailing_whitespace= >> AC_DEFINE_UNQUOTED([TRAILING_WHITESPACE], [$trailing_whitespace], >> [trailing whitespace]) >> >> Previously it would have trailing whitespace instead of /**/ causing >> annoying GCC warnings. > > Thanks for the patch; however, the awk logic needs to handle arbitrary > sequences of spaces and tabs, not just a single space. (It can map > them all to " /**/"; we're generating a C #define directive, so we know > that all nonempty sequences of spaces and tabs are equivalent in context.) > > Please also add a test case.
Done with the attached v2 patch. Also, I assume this patch will require a copyright assignment. So I will send that now. Collin
>From 1fab41362284b90ba7266d259e999a1dde6a0c9f Mon Sep 17 00:00:00 2001 Message-ID: <1fab41362284b90ba7266d259e999a1dde6a0c9f.1759604999.git.collin.fu...@gmail.com> From: Collin Funk <[email protected]> Date: Fri, 3 Oct 2025 22:57:05 -0700 Subject: [PATCH v2] Avoid -Wtrailing-whitespace in config.h. * lib/autoconf/status.m4: Replace empty definitions with /**/. * tests/torture.at (Replace empty macros with /**/): New test. --- lib/autoconf/status.m4 | 12 +++++++++++ tests/torture.at | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4 index 0ac451dc..39a38058 100644 --- a/lib/autoconf/status.m4 +++ b/lib/autoconf/status.m4 @@ -838,6 +838,18 @@ m4_define([_AC_OUTPUT_HEADERS_PREPARE] macro = mac2[1] prefix = substr(line, 1, index(line, defundef) - 1) if (D_is_set[macro]) { + # Set empty macros to /**/ to avoid -Wtrailing-whitespace. + allwhitespace = 1 + for (i = 0; i <= length(D[macro]); ++i) { + character = substr(D[macro], i, 1) + if (character != " " && character != " ") { + allwhitespace = 0 + break + } + } + if (allwhitespace == 1) { + D[macro] = " /**/" + } # Preserve the white space surrounding the "#". print prefix "define", macro P[macro] D[macro] next diff --git a/tests/torture.at b/tests/torture.at index 0e14315e..e1ff690e 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -1029,6 +1029,51 @@ X@file@ done AT_CLEANUP +## ------------------------------------------ ## +## Replace empty macros with /**/. ## +## ------------------------------------------ ## +AT_SETUP([Replace empty macros with /**/]) +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
