From b323b5297757c5c904e6aff63454c777703361ce Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 24 Jan 2023 13:44:07 +0100 Subject: [PATCH] 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 has not been fully included yet. --- ChangeLog | 7 +++++++ m4/stdalign.m4 | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 759310346b..f999f105a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-01-24 Bruno Haible + + 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 + has not been fully included yet. + 2023-01-22 Bruno Haible doc: Update list of target platforms. diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 index 0bb9281f5e..6a0ab2c102 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -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)) -- 2.34.1