]> Savannah Git Hosting - gnulib.git/commitdiff
alignasof, stdalign: Fix a compilation error on FreeBSD 12.0.
authorBruno Haible <bruno@clisp.org>
Tue, 24 Jan 2023 12:44:07 +0000 (13:44 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 24 Jan 2023 12:44:07 +0000 (13:44 +0100)
* m4/stdalign.m4 (gl_ALIGNASOF): In C mode, prefer __builtin_offsetof
over offsetof when possible, since __builtin_offsetof works also when
<stddef.h> has not been fully included yet.

ChangeLog
m4/stdalign.m4

index 759310346be6c1b7af368bf5e6171300d88d2368..f999f105a55fb38e5a3e42a0a60e80b580ea3b5a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-01-24  Bruno Haible  <bruno@clisp.org>
+
+       alignasof, stdalign: Fix a compilation error on FreeBSD 12.0.
+       * m4/stdalign.m4 (gl_ALIGNASOF): In C mode, prefer __builtin_offsetof
+       over offsetof when possible, since __builtin_offsetof works also when
+       <stddef.h> has not been fully included yet.
+
 2023-01-22  Bruno Haible  <bruno@clisp.org>
 
        doc: Update list of target platforms.
index 0bb9281f5ee49783c5fea7bd5c15f13d48840275..6a0ab2c1020d5dcac5b8ff36a78684388d033e7e 100644 (file)
@@ -112,8 +112,12 @@ AC_DEFUN([gl_ALIGNASOF],
 #      define _GL_STDALIGN_NEEDS_STDDEF 1
 #     endif
 #    else
-#     define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
-#     define _GL_STDALIGN_NEEDS_STDDEF 1
+#     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
 #   endif
 #   if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))