summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--m4/stdalign.m461
2 files changed, 67 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f3468e241f..76287c5022 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
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.
* lib/stdalign.in.h: Treat MSVC in C++ mode like C++11 compliant
compilers.
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])
])