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

ChangeLog
lib/stdalign.in.h
m4/stdalign.m4

index ca8306d1e4d5ef9c0b7a088394c9be679d7fdc77..bd7fd9ab5d0ead5efad5f121fb26d71c3f29645d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-01-24  Bruno Haible  <bruno@clisp.org>
+
+       stdalign: Fix a compilation error on FreeBSD 12.0.
+       * lib/stdalign.in.h (_Alignof): In C mode, prefer __builtin_offsetof
+       over offsetof when possible, since __builtin_offsetof works also when
+       <stddef.h> has not been fully included yet.
+       * m4/stdalign.m4 (gl_STDALIGN_H): Likewise.
+
 2023-01-22  Paul Eggert  <eggert@cs.ucla.edu>
 
        sigsegv, vma-iter: port to Solaris 10
index 17357810c7c23398ad5779b0d2e32fd735284a02..7f9dbb466e91a8cb581ac21488a9fa42e00f34a0 100644 (file)
 #   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))
index b1438eeaced818808ba524b0630971fc338eb8cd..dc2971753d6febe5abec1b413081405f6bfa2e50 100644 (file)
@@ -93,8 +93,12 @@ AC_DEFUN([gl_STDALIGN_H],
 #      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))