From: Bruno Haible Date: Mon, 21 Aug 2023 15:23:41 +0000 (+0200) Subject: alignasof, stdalign: Fix a compilation error in C++ mode on FreeBSD 12. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e69b0dfe6a9bf33b614751a54f329aea51a7983d;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 2c85e7f5cc..f57dfdfa55 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 dc2971753d..517c6b426a 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -89,7 +89,11 @@ AC_DEFUN([gl_STDALIGN_H], # 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