From a0a66677c799569b6e253379cf25d4181c85dc1d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 21 Aug 2023 17:23:41 +0200 Subject: [PATCH] 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 has not been fully included yet. --- ChangeLog | 7 +++++++ m4/stdalign.m4 | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0856abd4f0..1aa0e97f31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-08-21 Bruno Haible + + 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 + has not been fully included yet. + 2023-08-21 Bruno Haible wcsstr: Relicense under LGPLv2+. diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 index 6a39ffe756..5880efb2eb 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -112,7 +112,11 @@ AC_DEFUN([gl_ALIGNASOF], # define _Alignof(type) alignof (type) # else template struct __alignof_helper { char __a; __t __b; }; -# define _Alignof(type) offsetof (__alignof_helper, __b) +# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__ +# define _Alignof(type) __builtin_offsetof (__alignof_helper, __b) +# else +# define _Alignof(type) offsetof (__alignof_helper, __b) +# endif # define _GL_STDALIGN_NEEDS_STDDEF 1 # endif # else -- 2.39.5