diff options
Diffstat (limited to 'm4/stdalign.m4')
-rw-r--r-- | m4/stdalign.m4 | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 index 1a236d6..e3c1e60 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -1,6 +1,6 @@ # Check for alignas and alignof that conform to C23. -dnl Copyright 2011-2023 Free Software Foundation, Inc. +dnl Copyright 2011-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -13,10 +13,10 @@ AC_DEFUN([gl_ALIGNASOF], [ AC_CACHE_CHECK([for alignas and alignof], [gl_cv_header_working_stdalign_h], - [gl_save_CFLAGS=$CFLAGS + [gl_saved_CFLAGS=$CFLAGS for gl_working in "yes, keywords" "yes, <stdalign.h> macros"; do AS_CASE([$gl_working], - [*stdalign.h*], [CFLAGS="$gl_save_CFLAGS -DINCLUDE_STDALIGN_H"]) + [*stdalign.h*], [CFLAGS="$gl_saved_CFLAGS -DINCLUDE_STDALIGN_H"]) AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [[#include <stdint.h> @@ -56,7 +56,7 @@ AC_DEFUN([gl_ALIGNASOF], [gl_cv_header_working_stdalign_h=$gl_working], [gl_cv_header_working_stdalign_h=no]) - CFLAGS=$gl_save_CFLAGS + CFLAGS=$gl_saved_CFLAGS test "$gl_cv_header_working_stdalign_h" != no && break done]) @@ -68,8 +68,10 @@ AC_DEFUN([gl_ALIGNASOF], dnl The "zz" puts this toward config.h's end, to avoid potential dnl collisions with other definitions. AH_VERBATIM([zzalignas], -[#if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 && !defined alignof -# if HAVE_STDALIGN_H +[#if !defined HAVE_C_ALIGNASOF \ + && !(defined __cplusplus && 201103 <= __cplusplus) \ + && !defined alignof +# if defined HAVE_STDALIGN_H # include <stdalign.h> # endif @@ -110,7 +112,11 @@ AC_DEFUN([gl_ALIGNASOF], # 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 @@ -166,7 +172,7 @@ AC_DEFUN([gl_ALIGNASOF], # define _Alignas(a) __declspec (align (a)) # endif # endif -# if !HAVE_STDALIGN_H +# if !defined HAVE_STDALIGN_H # if ((defined _Alignas \ && !(defined __cplusplus \ && (201103 <= __cplusplus || defined _MSC_VER))) \ @@ -175,7 +181,7 @@ AC_DEFUN([gl_ALIGNASOF], # endif # endif -# if _GL_STDALIGN_NEEDS_STDDEF +# if defined _GL_STDALIGN_NEEDS_STDDEF # include <stddef.h> # endif #endif]) |