]> 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>
Mon, 21 Aug 2023 15:24:23 +0000 (17:24 +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 054f07345ae4f7ee5f6cdbbdca1fc8102320b2f0..a0e6b79f906e80e150454466a17c8586da19b027 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