>From 699f559a3d30e7e0c8e20d546e25f2743f2569d1 Mon Sep 17 00:00:00 2001 From: Bruno Haible 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 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 + + 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 but instead put the substitute code + into config.h. + 2022-09-24 Bruno Haible 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 +# if HAVE_STDALIGN_H +# include +# 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 struct __alignof_helper { char __a; __t __b; }; +# define _Alignof(type) offsetof (__alignof_helper, __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 +# endif +# endif /* _GL_STDALIGN_H */ +# endif #endif]) ]) -- 2.34.1