]> Savannah Git Hosting - gnulib.git/commitdiff
alignasof: Ensure a correct _Alignof (regression 2023-01-15).
authorBruno Haible <bruno@clisp.org>
Sat, 28 Jan 2023 01:55:06 +0000 (02:55 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 28 Jan 2023 02:23:17 +0000 (03:23 +0100)
* m4/stdalign.m4 (gl_ALIGNASOF): Apply the workaround for wrong _Alignof
in GCC < 4.9 and clang < 8.0.0 also when the system has <stdalign.h>.

ChangeLog
m4/stdalign.m4

index 34514a6d9acf740e789e02a070e5bd6d9a7e9653..f969177275a92b37eda022c402b90e6e72573196 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-01-27  Bruno Haible  <bruno@clisp.org>
+
+       alignasof: Ensure a correct _Alignof (regression 2023-01-15).
+       * m4/stdalign.m4 (gl_ALIGNASOF): Apply the workaround for wrong _Alignof
+       in GCC < 4.9 and clang < 8.0.0 also when the system has <stdalign.h>.
+
 2023-01-27  Bruno Haible  <bruno@clisp.org>
 
        stdalign: Ensure alignof is defined on FreeBSD (regression 2023-01-15).
index 3e83a2ca587209c1265216533375a5f225efb827..f49cf8ec1624666b11b3fa011b02e2260361efad 100644 (file)
@@ -71,7 +71,8 @@ AC_DEFUN([gl_ALIGNASOF],
 [#if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 && !defined alignof
 # if HAVE_STDALIGN_H
 #  include <stdalign.h>
-# else
+# endif
+
 /* ISO C23 alignas and alignof for platforms that lack it.
 
    References:
@@ -99,30 +100,32 @@ AC_DEFUN([gl_ALIGNASOF],
 /* GCC releases before GCC 4.9 had a bug in _Alignof.  See GCC bug 52023
    <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
    clang versions < 8.0.0 have the same bug.  */
-#   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
+#  if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
+       || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
+           && !defined __clang__) \
+       || (defined __clang__ && __clang_major__ < 8))
+#   undef/**/_Alignof
+#   ifdef __cplusplus
+#    if (201103 <= __cplusplus || defined _MSC_VER)
+#     define _Alignof(type) alignof (type)
 #    else
-#     if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
-#      define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
-#     else
-#      define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
-#      define _GL_STDALIGN_NEEDS_STDDEF 1
-#     endif
+      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
+#    if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
+#     define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
+#    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
+#  endif
+#  if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
+#   undef/**/alignof
+#   define alignof _Alignof
+#  endif
 
 /* alignas (A), also known as _Alignas (A), aligns a variable or type
    to the alignment A, where A is an integer constant expression.  For
@@ -148,6 +151,7 @@ AC_DEFUN([gl_ALIGNASOF],
      - alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
 
    */
+# if !HAVE_STDALIGN_H
 #  if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
 #   if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)
 #    define _Alignas(a) alignas (a)
@@ -169,9 +173,10 @@ AC_DEFUN([gl_ALIGNASOF],
        || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
 #   define alignas _Alignas
 #  endif
-#  if _GL_STDALIGN_NEEDS_STDDEF
-#   include <stddef.h>
-#  endif
+# endif
+
+# if _GL_STDALIGN_NEEDS_STDDEF
+#  include <stddef.h>
 # endif
 #endif])
 ])