]> Savannah Git Hosting - gnulib.git/commitdiff
alignasof, stdalign: Fix a compilation error in C++ mode on FreeBSD 12.
authorBruno Haible <bruno@clisp.org>
Mon, 21 Aug 2023 15:23:41 +0000 (17:23 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 30 Aug 2023 10:00:38 +0000 (12:00 +0200)
* 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 0856abd4f028b2cc66b98764144b79e9453059ba..1aa0e97f315b0766c184f36cbfd9cfca4d798b68 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-08-21  Bruno Haible  <bruno@clisp.org>
+
+       alignasof, stdalign: Fix a compilation error in C++ mode on FreeBSD 12.
+       * 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-08-21  Bruno Haible  <bruno@clisp.org>
 
        wcsstr: Relicense under LGPLv2+.
index 6a39ffe756581584e7b5aef891f876aafd412e43..5880efb2ebf98f2f3534b9bf118369b874c65c64 100644 (file)
@@ -112,7 +112,11 @@ AC_DEFUN([gl_ALIGNASOF],
 #     define _Alignof(type) alignof (type)
 #    else
       template <class __t> struct __alignof_helper { char __a; __t __b; };
-#     define _Alignof(type) offsetof (__alignof_helper<type>, __b)
+#     if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
+#      define _Alignof(type) __builtin_offsetof (__alignof_helper<type>, __b)
+#     else
+#      define _Alignof(type) offsetof (__alignof_helper<type>, __b)
+#     endif
 #     define _GL_STDALIGN_NEEDS_STDDEF 1
 #    endif
 #   else