Hi Paul,

> * lib/stddef.in.h: Do nothing if _@GUARD_PREFIX@_STDDEF_H is
> defined, as stddef.h has already been included.  This works
> around GCC bug 114870.

I had to revert this, since it broke Cygwin.

The workaround should be as platform specific as possible, since
fiddling with the __need_wchar_t etc. invocation convention is
risky: it is used by several platforms: older Mac OS X, Haiku, Cygwin,
and glibc.

Fortunately you already wrote the configure test for it. I only need
to pull it in.

I tried another workaround, consisting of adding
  #undef __STDC_VERSION_STDDEF_H__
at the appropriate place, but then the Fedora 40 gcc gives a warning
about this #undef. Since neither the warning about the redefinition
nor the warning about the #undef can be silenced via
  #pragma GCC diagnostic ignored "-W..."
this approach did not work.


2024-05-01  Bruno Haible  <br...@clisp.org>

        stddef: A better workaround against GCC bug 114870.
        * lib/stddef.in.h: If STDDEF_NOT_IDEMPOTENT is 1, disable the special
        invocation convention.
        * m4/stddef_h.m4 (gl_STDDEF_H): Set STDDEF_NOT_IDEMPOTENT.
        (gl_STDDEF_H_DEFAULTS): Initialize STDDEF_NOT_IDEMPOTENT.
        * modules/stddef (Makefile.am): Substitute STDDEF_NOT_IDEMPOTENT.

diff --git a/lib/stddef.in.h b/lib/stddef.in.h
index ac81257b5c..63bb500e26 100644
--- a/lib/stddef.in.h
+++ b/lib/stddef.in.h
@@ -27,9 +27,13 @@
 #endif
 @PRAGMA_COLUMNS@
 
-#if (defined __need_wchar_t || defined __need_size_t \
-     || defined __need_ptrdiff_t || defined __need_NULL \
-     || defined __need_wint_t)
+#if (defined __need_wchar_t || defined __need_size_t                \
+     || defined __need_ptrdiff_t || defined __need_NULL             \
+     || defined __need_wint_t)                                      \
+    /* Avoid warning triggered by "gcc -std=gnu23 -Wsystem-headers" \
+       in Fedora 40 with gcc 14.0.1.                                \
+       <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870>.  */   \
+    && !@STDDEF_NOT_IDEMPOTENT@
 /* Special invocation convention inside gcc header files.  In
    particular, <stddef.h> in some ancient versions of GCC blindly
    redefined NULL when __need_wint_t was defined, even though wint_t
@@ -56,6 +60,13 @@
 # endif
 
 #else
+/* For @STDDEF_NOT_IDEMPOTENT@.  */
+# undef __need_wchar_t
+# undef __need_size_t
+# undef __need_ptrdiff_t
+# undef __need_NULL
+# undef __need_wint_t
+
 /* Normal invocation convention.  */
 
 # ifndef _@GUARD_PREFIX@_STDDEF_H
diff --git a/m4/stddef_h.m4 b/m4/stddef_h.m4
index 0d4ddf8fcb..998fe12fa8 100644
--- a/m4/stddef_h.m4
+++ b/m4/stddef_h.m4
@@ -1,5 +1,5 @@
 # stddef_h.m4
-# serial 15
+# serial 16
 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -110,6 +110,7 @@ AC_DEFUN_ONCE([gl_STDDEF_H]
         [gl_cv_clean_version_stddef=yes],
         [gl_cv_clean_version_stddef=no])])
   if test "$gl_cv_clean_version_stddef" = no; then
+    STDDEF_NOT_IDEMPOTENT=1
     GL_GENERATE_STDDEF_H=true
   fi
 
@@ -144,6 +145,7 @@ AC_DEFUN([gl_STDDEF_H_DEFAULTS]
 [
   dnl Assume proper GNU behavior unless another module says otherwise.
   NULLPTR_T_NEEDS_STDDEF=1;      AC_SUBST([NULLPTR_T_NEEDS_STDDEF])
+  STDDEF_NOT_IDEMPOTENT=0;       AC_SUBST([STDDEF_NOT_IDEMPOTENT])
   REPLACE_NULL=0;                AC_SUBST([REPLACE_NULL])
   HAVE_MAX_ALIGN_T=1;            AC_SUBST([HAVE_MAX_ALIGN_T])
   HAVE_WCHAR_T=1;                AC_SUBST([HAVE_WCHAR_T])
diff --git a/modules/stddef b/modules/stddef
index 4096ab955d..9a80db007b 100644
--- a/modules/stddef
+++ b/modules/stddef
@@ -31,10 +31,11 @@ stddef.h: stddef.in.h $(top_builddir)/config.status
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \
-             -e 's|@''HAVE_MAX_ALIGN_T''@|$(HAVE_MAX_ALIGN_T)|g' \
-             -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \
              -e 's|@''NULLPTR_T_NEEDS_STDDEF''@|$(NULLPTR_T_NEEDS_STDDEF)|g' \
+             -e 's|@''STDDEF_NOT_IDEMPOTENT''@|$(STDDEF_NOT_IDEMPOTENT)|g' \
              -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \
+             -e 's|@''HAVE_MAX_ALIGN_T''@|$(HAVE_MAX_ALIGN_T)|g' \
+             -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \
              $(srcdir)/stddef.in.h > $@-t
        $(AM_V_at)mv $@-t $@
 else




Reply via email to