With the current gnulib, I'm getting two new test failures of 'lang-c' and
'lang-c++' in GNU gettext. 'lang-c' for example fails to compile the sample
program:


FAIL: lang-c
============

prog.c
../..\config.h(3288): fatal error C1083: Cannot open include file: 
'stdalign.h': No such file or directory
FAIL lang-c (exit status: 1)


The gettext sample programs include <config.h>. On this platform, there is no
<stdalign.h>, and thus stdalign.m4 has stuffed a
  #include <stdalign.h>
into config.h, intending to include the gnulib-generated stdalign.h.

This is problematic for three reasons:

  * Since the gnulib-generated stdalign.h is in a different directory than
    config.h, the compilation command needs additional -I options. This is
    likely to occur not only in GNU gettext, but also in other packages.
    And adding such -I options may cause other generated .h files
    (stdio.h, unistd.h, etc.) to become visible, which can activate some
    rpl_ substitutes and thus cause link errors.

  * There can be several gnulib-tool invocations in the scope of a single
    configure.ac and config.h. It is not even clear to the package maintainer
    from which gnulib build directory to take stdalign.h.

  * stdalign.h is created by "make" — after config.h, which is created by
    config.status. And similarly, "make clean" erases stdalign.h but not
    config.h. So, for some time, we have a config.h file which includes a
    nonexistent file. This too can cause all sorts of trouble that will
    be difficult to track down by the package maintainer.

Thus, it's best to avoid such a situation. This holds not only for
<stdalign.h> but also for <stdbool.h>. For <assert.h> on the other hand
I think the trouble is limited, because <assert.h> always exists among the
system header files.

The attached patches do this. Note that this raises a question how to get
along with an AC_C_BOOL macro, since obviously Autoconf cannot be kept
in sync with Gnulib. Maybe AC_C_BOOL will need to take an optional argument
AC_C_BOOL([substitute for stdbool.h]) ?


2022-09-24  Bruno Haible  <br...@clisp.org>

        stdbool: Don't #include a gnulib-generated stdbool.h from config.h.
        * m4/c-bool.m4 (gl_C_BOOL): Check for stdbool.h and for _Bool. If
        stdbool.h does not exist, don't #include <stdbool.h> but instead put the
        substitute code into config.h.

2022-09-24  Bruno Haible  <br...@clisp.org>

        stdalign: Don't #include a gnulib-generated stdalign.h from config.h.
        * m4/stdalign.m4 (gl_STDALIGN_H): Check for stdalign.h. If it does not
        exist, don't #include <stdalign.h> but instead put the substitute code
        into config.h.

>From 699f559a3d30e7e0c8e20d546e25f2743f2569d1 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 24 Sep 2022 19:56:31 +0200
Subject: [PATCH 1/2] stdalign: Don't #include a gnulib-generated stdalign.h
 from config.h.

* m4/stdalign.m4 (gl_STDALIGN_H): Check for stdalign.h. If it does not
exist, don't #include <stdalign.h> but instead put the substitute code
into config.h.
---
 ChangeLog      |  7 ++++++
 m4/stdalign.m4 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index f3468e241f..76287c5022 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-24  Bruno Haible  <br...@clisp.org>
+
+	stdalign: Don't #include a gnulib-generated stdalign.h from config.h.
+	* m4/stdalign.m4 (gl_STDALIGN_H): Check for stdalign.h. If it does not
+	exist, don't #include <stdalign.h> but instead put the substitute code
+	into config.h.
+
 2022-09-24  Bruno Haible  <br...@clisp.org>
 
 	stdalign: Fix compilation error with MSVC in C++ mode.
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index 9164c2f357..324e91dae2 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -66,10 +66,69 @@ AC_DEFUN([gl_STDALIGN_H],
       [AC_DEFINE([HAVE_C_ALIGNASOF], [1],
          [Define to 1 if the alignas and alignof keywords work.])])
 
+  AC_CHECK_HEADERS_ONCE([stdalign.h])
+
   dnl The "zz" puts this toward config.h's end, to avoid potential
   dnl collisions with other definitions.
   AH_VERBATIM([zzalignas],
 [#if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 && !defined alignof
- #include <stdalign.h>
+# if HAVE_STDALIGN_H
+#  include <stdalign.h>
+# else
+   /* Substitute.  Keep consistent with gnulib/lib/stdalign.in.h.  */
+#  ifndef _GL_STDALIGN_H
+#   define _GL_STDALIGN_H
+#   undef _Alignas
+#   undef _Alignof
+#   if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
+        || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
+            && !defined __clang__) \
+        || (defined __clang__ && __clang_major__ < 8))
+#    ifdef __cplusplus
+#     if (201103 <= __cplusplus || defined _MSC_VER)
+#      define _Alignof(type) alignof (type)
+#     else
+       template <class __t> struct __alignof_helper { char __a; __t __b; };
+#      define _Alignof(type) offsetof (__alignof_helper<type>, __b)
+#      define _GL_STDALIGN_NEEDS_STDDEF 1
+#     endif
+#    else
+#     define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
+#     define _GL_STDALIGN_NEEDS_STDDEF 1
+#    endif
+#   endif
+#   if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
+#    define alignof _Alignof
+#   endif
+#   define __alignof_is_defined 1
+#   if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
+#    if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)
+#     define _Alignas(a) alignas (a)
+#    elif (!defined __attribute__ \
+           && ((defined __APPLE__ && defined __MACH__ \
+                ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
+                : __GNUC__ && !defined __ibmxl__) \
+               || (4 <= __clang_major__) \
+               || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
+               || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
+#     define _Alignas(a) __attribute__ ((__aligned__ (a)))
+#    elif 1300 <= _MSC_VER
+#     define _Alignas(a) __declspec (align (a))
+#    endif
+#   endif
+#   if ((defined _Alignas \
+         && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \
+        || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
+#    define alignas _Alignas
+#   endif
+#   if (defined alignas \
+        || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)))
+#    define __alignas_is_defined 1
+#   endif
+#   if _GL_STDALIGN_NEEDS_STDDEF
+#    include <stddef.h>
+#   endif
+#  endif /* _GL_STDALIGN_H */
+# endif
 #endif])
 ])
-- 
2.34.1

>From 2eb78f0716542854209a35d7ea5bd2d38ef32582 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 24 Sep 2022 23:42:44 +0200
Subject: [PATCH 2/2] stdbool: Don't #include a gnulib-generated stdbool.h from
 config.h.

* m4/c-bool.m4 (gl_C_BOOL): Check for stdbool.h and for _Bool. If
stdbool.h does not exist, don't #include <stdbool.h> but instead put the
substitute code into config.h.
---
 ChangeLog       |  7 +++++++
 m4/c-bool.m4    | 42 +++++++++++++++++++++++++++++++++++++++++-
 modules/stdbool |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 76287c5022..1c54eabb49 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-24  Bruno Haible  <br...@clisp.org>
+
+	stdbool: Don't #include a gnulib-generated stdbool.h from config.h.
+	* m4/c-bool.m4 (gl_C_BOOL): Check for stdbool.h and for _Bool. If
+	stdbool.h does not exist, don't #include <stdbool.h> but instead put the
+	substitute code into config.h.
+
 2022-09-24  Bruno Haible  <br...@clisp.org>
 
 	stdalign: Don't #include a gnulib-generated stdalign.h from config.h.
diff --git a/m4/c-bool.m4 b/m4/c-bool.m4
index 67c2cf2621..129981d2f7 100644
--- a/m4/c-bool.m4
+++ b/m4/c-bool.m4
@@ -22,6 +22,10 @@ AC_DEFUN([gl_C_BOOL],
       [Define to 1 if bool, true and false work as per C2023.])
   fi
 
+  AC_CHECK_HEADERS_ONCE([stdbool.h])
+  AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
+  AC_DEFINE_UNQUOTED([HAVE__BOOL],[$HAVE__BOOL])
+
   dnl The "zz" puts this toward config.h's end, to avoid potential
   dnl collisions with other definitions.
   dnl If 'bool', 'true' and 'false' do not work, arrange for them to work.
@@ -32,7 +36,43 @@ AC_DEFUN([gl_C_BOOL],
   AH_VERBATIM([zzbool],
 [#ifndef HAVE_C_BOOL
 # if !defined __cplusplus && !defined __bool_true_false_are_defined
-#  include <stdbool.h>
+#  if HAVE_STDBOOL_H
+#   include <stdbool.h>
+#  else
+    /* Substitute.  Keep consistent with gnulib/lib/stdbool.in.h.  */
+#   ifndef _GL_STDBOOL_H
+#    define _GL_STDBOOL_H
+#    ifdef __cplusplus
+#     if !defined _MSC_VER
+#      define _Bool bool
+#      define bool bool
+#     endif
+#    else
+#     if !defined __GNUC__
+#      define _Bool signed char
+#     else
+#      if !HAVE__BOOL
+typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
+#      endif
+#     endif
+#     define bool _Bool
+#    endif
+#    ifdef __cplusplus
+#     if !defined _MSC_VER
+#      define false false
+#      define true true
+#     endif
+#     if defined __SUNPRO_CC && true != 1
+#      undef true
+#      define true (!false)
+#     endif
+#    else
+#     define false 0
+#     define true 1
+#    endif
+#    define __bool_true_false_are_defined 1
+#   endif /* _GL_STDBOOL_H */
+#  endif
 # endif
 # if !true
 #  define true (!false)
diff --git a/modules/stdbool b/modules/stdbool
index 2e771a2336..664df5e0f8 100644
--- a/modules/stdbool
+++ b/modules/stdbool
@@ -3,6 +3,7 @@ A bool that is like C23.
 
 Files:
 m4/c-bool.m4
+m4/stdbool.m4
 
 Depends-on:
 c99
-- 
2.34.1

Reply via email to