]> Savannah Git Hosting - gnulib.git/commitdiff
stdalign: Don't #include a gnulib-generated stdalign.h from config.h.
authorBruno Haible <bruno@clisp.org>
Sat, 24 Sep 2022 17:56:31 +0000 (19:56 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 24 Sep 2022 22:46:24 +0000 (00:46 +0200)
* 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
m4/stdalign.m4

index f3468e241fa12c902c5f3c9a75653c63d31a5f5e..76287c50229a3a723121a34a9fdebc535fa15f1b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-24  Bruno Haible  <bruno@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  <bruno@clisp.org>
 
        stdalign: Fix compilation error with MSVC in C++ mode.
index 9164c2f35703ffd27502d60fa16a630ffbd3f66a..324e91dae2e09a6e1a60414137c65b315ccdfcb4 100644 (file)
@@ -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])
 ])