]> 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:23:43 +0000 (12:23 +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 2c85e7f5cc23db8874db62d54a93fc1d4dec4dcf..f57dfdfa555fe8a7310969e779b2353314488819 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 dc2971753d6febe5abec1b413081405f6bfa2e50..517c6b426ab3193ab69468857250c663f35ba692 100644 (file)
@@ -89,7 +89,11 @@ AC_DEFUN([gl_STDALIGN_H],
 #      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