On 2026-04-29 15:03, Bruno Haible wrote:
I thought I was clear regarding the test recipe. In any case, here it is
Sorry, you probably were clear but I misunderstood. Anyway, I reproduced
the problem on Fedora 43 with G++ 15.2.1 (where <stdbit.h> does nothing
when __cplusplus <= 202302L), and installed the attached which works for
me. Perhaps at some point we'll need to complicate things by splitting
@HAVE_STDBIT_H@ into @HAVE_CXX_STDBIT_H@ and @HAVE_C_STDBIT_@, as we
already do for @HAVE_STDCKDINT_H@, but I hope we don't have to do that.
It is curious that a C++ compiler would silently ignore an "#include
<stdbit.h>" that works fine in the corresponding C compiler. Wouldn't it
be better to diagnose the directive? Is there a C++ tradition to ignore
"#include <X>" directives when <X> is taken from a future C++ standard?From 66763ea9a77ea04b9c6feeefa6a37903b979a6fe Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Wed, 29 Apr 2026 17:10:56 -0700
Subject: [PATCH] stdbit-h: namespace cleanup port to G++ 15
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
For the namespace cleanup, don’t assume that the system <stdbit.h>
defines size_t etc. unless it also defines
__STDC_VERSION_STDBIT_H__. This works around problems with C++
compilers where ‘#include <stdbit.h>’ is a no-op, such as g++ 15.2.1.
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2026-04/msg00203.html
It also lets us simplify the code by removing a special case for
the Intel icpx C++ compiler.
* lib/stdbit.in.h: When deciding whether <stdbit.h> works,
use (defined __STDC_VERSION_STDBIT_H__) rather than @HAVE_STDBIT_H@.
This fixes problems when <stdbit.h> works for C so @HAVE_STDBIT_H@
is 1, whereas <stdbit.h> does nothing for C++.
(__STDC_VERSION_STDBIT_H__): Move definition to end.
---
ChangeLog | 15 +++++++++++++++
doc/posix-headers/stdbit.texi | 3 +++
lib/stdbit.in.h | 23 ++++++++++-------------
3 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 86585c6ff6..98aff8ecd2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2026-04-29 Paul Eggert <[email protected]>
+ stdbit-h: namespace cleanup port to G++ 15
+ For the namespace cleanup, don’t assume that the system <stdbit.h>
+ defines size_t etc. unless it also defines
+ __STDC_VERSION_STDBIT_H__. This works around problems with C++
+ compilers where ‘#include <stdbit.h>’ is a no-op, such as g++ 15.2.1.
+ Problem reported by Bruno Haible in:
+ https://lists.gnu.org/r/bug-gnulib/2026-04/msg00203.html
+ It also lets us simplify the code by removing a special case for
+ the Intel icpx C++ compiler.
+ * lib/stdbit.in.h: When deciding whether <stdbit.h> works,
+ use (defined __STDC_VERSION_STDBIT_H__) rather than @HAVE_STDBIT_H@.
+ This fixes problems when <stdbit.h> works for C so @HAVE_STDBIT_H@
+ is 1, whereas <stdbit.h> does nothing for C++.
+ (__STDC_VERSION_STDBIT_H__): Move definition to end.
+
stdbit-h: <stddef.h> namespace cleanup
* lib/stdbit.in.h: Include <stddef.h> only if the stdc_memreverse8
module is also used, since it’s the only one that needs size_t.
diff --git a/doc/posix-headers/stdbit.texi b/doc/posix-headers/stdbit.texi
index 87f91d0a54..b658447021 100644
--- a/doc/posix-headers/stdbit.texi
+++ b/doc/posix-headers/stdbit.texi
@@ -15,6 +15,9 @@ stdbit.h
This header file is missing on many non-C23 platforms:
glibc 2.38, macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, AIX 7.3.1, HP-UX 11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
@item
+This header file exists but is a no-op:
+G++ 15.2.
+@item
This header file does not define the necessary types
with the Intel @code{icpx} C++ compiler.
@end itemize
diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h
index 04a9dfd183..990f3edfde 100644
--- a/lib/stdbit.in.h
+++ b/lib/stdbit.in.h
@@ -38,9 +38,7 @@
#endif
/* If needed for APIs, get size_t, avoiding namespace pollution on GNU. */
-#if (@GNULIB_STDC_MEMREVERSE8@ \
- && (!@HAVE_STDBIT_H@ \
- || (defined __cplusplus && defined __INTEL_CLANG_COMPILER)))
+#if @GNULIB_STDC_MEMREVERSE8@ && !defined __STDC_VERSION_STDBIT_H__
# define __need_size_t
# include <stddef.h>
#endif
@@ -51,8 +49,7 @@
#if (@GNULIB_STDC_MEMREVERSE8U@ \
|| @GNULIB_STDC_LOAD8@ || @GNULIB_STDC_LOAD8_ALIGNED@ \
|| @GNULIB_STDC_STORE8@ || @GNULIB_STDC_STORE8_ALIGNED@)
-# if (!(@HAVE_STDBIT_H@ && defined __UINT_FAST64_TYPE__) \
- || (defined __cplusplus && defined __INTEL_CLANG_COMPILER))
+# if !(defined __STDC_VERSION_STDBIT_H__ && defined __UINT_FAST64_TYPE__)
# include <stdint.h>
# define _GL_STDBIT_UINT_FAST16 uint_fast16_t
# define _GL_STDBIT_UINT_FAST32 uint_fast32_t
@@ -196,12 +193,7 @@ extern "C" {
/* Some systems are only missing C2y features in stdbit.h. */
-#if !@HAVE_STDBIT_H@ || defined __cplusplus
-
-/* ISO C 23 § 7.18.1 General */
-
-#define __STDC_VERSION_STDBIT_H__ 202311L
-
+#ifndef __STDC_VERSION_STDBIT_H__
/* ISO C 23 § 7.18.2 Endian */
@@ -217,7 +209,7 @@ extern "C" {
/* Some systems are only missing C2y features in stdbit.h. */
-#if !@HAVE_STDBIT_H@
+#ifndef __STDC_VERSION_STDBIT_H__
/* ISO C 23 § 7.18.3 Count Leading Zeros */
@@ -1263,7 +1255,7 @@ stdc_bit_ceil_ull (unsigned long long int n)
#endif
-#endif /* @HAVE_STDBIT_H@ */
+#endif /* !__STDC_VERSION_STDBIT_H__ */
/* ISO C2y § 7.18.17 Rotate Left */
@@ -2212,5 +2204,10 @@ stdc_store8_aligned_les64 (int_least64_t value, unsigned char ptr[8])
_GL_INLINE_HEADER_END
+/* ISO C 23 § 7.18.1 General */
+#ifndef __STDC_VERSION_STDBIT_H__
+# define __STDC_VERSION_STDBIT_H__ 202311L
+#endif
+
#endif /* _@GUARD_PREFIX@_STDBIT_H */
#endif /* _@GUARD_PREFIX@_STDBIT_H */
--
2.54.0