Re: problem building Gnulib libgnu_a-malloca.o with Debian oldstable's clang

Lasse Collin <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
On 2026-08-07 Paul Eggert wrote:
> On 8/7/26 10:57, Lasse Collin wrote:
> > I
> > don't know if this even needs to work because without
> > ac_cv_prog_cc_c23=no the compiler would be in GNU C11/C17 mode  
> 
> Yes. What happens if you remove the ac_cv_prog_cc_c11=no from 
> configure.ac? (You can keep the ac_cv_prog_cxx_cxx11=no line.) Again, 
> I'm looking for a simple fix.

Sorry, I meant to write _c11=no above, not _c23=no.

If the line ac_cv_prog_cc_c11=no is removed, then it works. That is,
after configuring with CC='clang -std=gnu99', Makefile has this:

    CC = clang -std=gnu99 -std=gnu11

It works even with Autoconf 2.69 because Gnulib's std-gnu11.m4 adds the
check for -std=gnu11 which Autoconf 2.69 itself doesn't have.

* * *

I looked at the root cause. In the Gnulib-generated assert.h in both
gnu99 and gnu11 modes, these look correct:

    _GL_HAVE__STATIC_ASSERT is defined.
    _GL_HAVE__STATIC_ASSERT1 is not defined.

In gnu11 mode, Gnulib-generated assert.h overrides _Static_assert here:

# elif !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
#  if !defined _MSC_VER || defined __clang__
#   define _Static_assert(...) \
      _GL_STATIC_ASSERT (__VA_ARGS__, "static assertion failed", -)

However, in gnu99 mode, no overriding happens because <sys/cdefs.h>
from glibc 2.31 has already defined _Static_assert (the old glibc lacks
the check for __clang_major__):

#if (!defined _Static_assert && !defined __cplusplus \
     && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
     && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
# define _Static_assert(expr, diagnostic) \
    extern int (*__Static_assert_function (void)) \
      [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
#endif

I attached patches. The first one adds a comment related to this issue.
The second patch fixes the groff build (even if ac_cv_prog_cc_c11=no
isn't removed). I didn't do other testing.

-- 
Lasse Collin
0001-verify-Add-a-comment-about-Clang-on-Mac-OS-10.7.5.patch (text/x-patch, 1.7 KB)
From 5bb11a0b5d0ada27eac01ff6127191c70d756273 Mon Sep 17 00:00:00 2001
From: Lasse Collin <[email protected]>
Date: Sat, 8 Aug 2026 13:30:08 +0300
Subject: [PATCH 1/2] verify: Add a comment about Clang on Mac OS 10.7.5

* lib/verify.h: The existing comment says "clang 4+" but the #if
checks for 5 <= __clang_major__. The mismatch looked like a bug.
Add a comment based on the commit 0cda5beb7962 ("verify: port to
Mac OS 10.7.5") to explain why the condition checks for 5 <=.
---
 ChangeLog    | 8 ++++++++
 lib/verify.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index dcc91e5ba5..9bb4925f75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-08-08  Lasse Collin  <[email protected]>
+
+	verify: Add a comment about Clang on Mac OS 10.7.5.
+	* lib/verify.h: The existing comment says "clang 4+" but the #if
+	checks for 5 <= __clang_major__. The mismatch looked like a bug.
+	Add a comment based on the commit 0cda5beb7962 ("verify: port to
+	Mac OS 10.7.5") to explain why the condition checks for 5 <=.
+
 2026-08-07  Bruno Haible  <[email protected]>
 
 	Fix position of _GL_ATTRIBUTE_REPRODUCIBLE in last commit.
diff --git a/lib/verify.h b/lib/verify.h
index 7daa20eb6f..7d3a6de49e 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -23,6 +23,8 @@
 
 /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC)
    works as per C11.  This is supported by GCC 4.6.0+ and by clang 4+.
+   Check for Clang >= 5 instead of >= 4 because clang on Mac OS 10.7.5
+   sets __clang_major__ to 4 even though it was derived from Clang 3.2.
 
    Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as
    per C23.  This is supported by GCC 9.1+.
-- 
2.55.0
0002-verify-Fix-single-argument-static_assert-with-glibc-.patch (text/x-patch, 2.1 KB)
From 79e9a4a0093ebdea1ea00f9d27f1a35120cdd511 Mon Sep 17 00:00:00 2001
From: Lasse Collin <[email protected]>
Date: Sat, 8 Aug 2026 13:30:08 +0300
Subject: [PATCH 2/2] verify: Fix single-argument static_assert with glibc in
 C89 & C99 modes

* lib/verify.h: glibc's <sys/cdefs.h> may define _Static_assert
with two arguments when the compiler is in C89 or C99 mode.
Undefine it so that Gnulib's own version is used instead.
Reported by G. Branden Robinson in
<https://lists.gnu.org/archive/html/bug-gnulib/2026-08/msg00125.html>.
---
 ChangeLog    |  9 +++++++++
 lib/verify.h | 10 ++++++++++
 2 files changed, 19 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 9bb4925f75..3f6840afb6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-08-08  Lasse Collin  <[email protected]>
+
+	verify: Fix single-argument static_assert with glibc in C89 & C99 modes.
+	* lib/verify.h: glibc's <sys/cdefs.h> may define _Static_assert
+	with two arguments when the compiler is in C89 or C99 mode.
+	Undefine it so that Gnulib's own version is used instead.
+	Reported by G. Branden Robinson in
+	<https://lists.gnu.org/archive/html/bug-gnulib/2026-08/msg00125.html>.
+
 2026-08-08  Lasse Collin  <[email protected]>
 
 	verify: Add a comment about Clang on Mac OS 10.7.5.
diff --git a/lib/verify.h b/lib/verify.h
index 7d3a6de49e..62a2bbca75 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -46,6 +46,16 @@
 # endif
 #endif
 
+/* <sys/cdefs.h> in glibc may define _Static_assert with two arguments if the
+   compiler is in C89 or C99 mode.  This matters especially with Clang:
+   (1) glibc < 2.34, before the commit c8ba52ab3350 ("misc: Sync cdefs.h
+       with gnulib"), doesn't check for __clang_major__ >= 4.
+   (2) The above condition for _GL_HAVE__STATIC_ASSERT checks for
+       __clang_major__ >= 5, so it's not in sync with glibc.  */
+#if __STDC_VERSION__ < 201112 && defined __GLIBC__
+# undef _Static_assert
+#endif
+
 /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
    system headers, defines a conflicting _Static_assert that is no
    better than ours; override it unless Gnulib's replacement <assert.h>
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.