* tests/test-stdalign.c: Do not test __alignas_is_defined, _Alignof, or _Alignas as they are obsolescent. Do not use __alignas_is_defined in C23 or later (or C++11 or later), as it’s removed in C23. --- ChangeLog | 8 ++++++++ doc/posix-headers/stdalign.texi | 12 ++++++++---- lib/alignof.h | 3 +-- tests/test-stdalign.c | 29 +++-------------------------- 4 files changed, 20 insertions(+), 32 deletions(-)
diff --git a/ChangeLog b/ChangeLog index d812e73f55..5013112632 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2022-09-13 Paul Eggert <egg...@cs.ucla.edu> + + stdalign-tests: port to C23 + * tests/test-stdalign.c: Do not test __alignas_is_defined, + _Alignof, or _Alignas as they are obsolescent. + Do not use __alignas_is_defined in C23 or later (or C++11 or later), + as it’s removed in C23. + 2022-09-12 Bruno Haible <br...@clisp.org> supersede: Avoid a failure when writing to /dev/null in Solaris zones. diff --git a/doc/posix-headers/stdalign.texi b/doc/posix-headers/stdalign.texi index 0f76bc90e6..4ed83bec3e 100644 --- a/doc/posix-headers/stdalign.texi +++ b/doc/posix-headers/stdalign.texi @@ -35,10 +35,9 @@ On most pre-C11 platforms, the operand of @code{alignof}/@code{_Alignof} cannot be a structure type containing a flexible array member. @item -@code{_Alignas} and @code{alignas} are not always supported; -on platforms lacking support, the -macro @code{__alignas_is_defined} is not defined. -Supported compilers include GCC, IBM C, Sun C 5.9 and later, +@code{_Alignas} and @code{alignas} are not always supported. +Supported compilers include any compiler supporting C11 or later, +which includes GCC, IBM C, Sun C 5.9 and later, and MSVC 7.0 and later. @item Some compilers do not support alignment via @@ -63,6 +62,11 @@ also known as Oracle Developer Studio 12.6. @code{<stdalign.h>} must be #included before @code{_Alignas} and @code{_Alignof} can be used. @item +In C11 and C17, @code{<stdalign.h>} defines the macros +@code{__alignas_is_defined} and +@code{__alignof_is_defined} to 1. +In C23, these macros are not defined. +@item You cannot assume that @code{_Alignas} and @code{_Alignof} are reserved words; they might be macros. @end itemize diff --git a/lib/alignof.h b/lib/alignof.h index 3f4a54257d..41bab60378 100644 --- a/lib/alignof.h +++ b/lib/alignof.h @@ -22,8 +22,7 @@ /* alignof_slot (TYPE) Determine the alignment of a structure slot (field) of a given type, at compile time. Note that the result depends on the ABI. - This is the same as alignof (TYPE) and _Alignof (TYPE), defined in - <stdalign.h> if __alignof_is_defined is 1. + This is the same as alignof (TYPE) and _Alignof (TYPE). Note: The result cannot be used as a value for an 'enum' constant, due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */ #if defined __cplusplus diff --git a/tests/test-stdalign.c b/tests/test-stdalign.c index 85d23a6eda..69268b87b4 100644 --- a/tests/test-stdalign.c +++ b/tests/test-stdalign.c @@ -33,21 +33,12 @@ typedef struct { char a[2]; } struct2; typedef struct { char a[3]; } struct3; typedef struct { char a[4]; } struct4; -verify (__alignof_is_defined == 1); -#ifndef alignof -# error "alignof is not a macro" -#endif - -#if __alignas_is_defined -verify (__alignas_is_defined == 1); -# ifndef alignas -# error "alignas is not a macro" -# endif +#if (202311 <= __STDC_VERSION__ || __alignas_is_defined \ + || 201103 <= __cplusplus) /* mingw can go up only to 8. 8 is all that GNU Emacs needs, so let's limit the test to 8 for now. */ # define TEST_ALIGNMENT 8 #else -# define _Alignas(alignment) # define alignas(alignment) # define TEST_ALIGNMENT 1 #endif @@ -55,10 +46,8 @@ verify (__alignas_is_defined == 1); #define CHECK_STATIC(type) \ typedef struct { char slot1; type slot2; } type##_helper; \ verify (alignof (type) == offsetof (type##_helper, slot2)); \ - verify (_Alignof (type) == alignof (type)); \ const int type##_alignment = alignof (type); \ - type alignas (TEST_ALIGNMENT) static_##type##_alignas; \ - type _Alignas (TEST_ALIGNMENT) static_##type##_Alignas + type alignas (TEST_ALIGNMENT) static_##type##_alignas #define CHECK_ALIGNED(var) ASSERT ((uintptr_t) &(var) % TEST_ALIGNMENT == 0) @@ -96,31 +85,19 @@ main () return 77; #else CHECK_ALIGNED (static_char_alignas); - CHECK_ALIGNED (static_char_Alignas); CHECK_ALIGNED (static_short_alignas); - CHECK_ALIGNED (static_short_Alignas); CHECK_ALIGNED (static_int_alignas); - CHECK_ALIGNED (static_int_Alignas); CHECK_ALIGNED (static_long_alignas); - CHECK_ALIGNED (static_long_Alignas); # ifdef INT64_MAX CHECK_ALIGNED (static_int64_t_alignas); - CHECK_ALIGNED (static_int64_t_Alignas); # endif CHECK_ALIGNED (static_float_alignas); - CHECK_ALIGNED (static_float_Alignas); CHECK_ALIGNED (static_double_alignas); - CHECK_ALIGNED (static_double_Alignas); /* CHECK_ALIGNED (static_longdouble_alignas); */ - /* CHECK_ALIGNED (static_longdouble_Alignas); */ CHECK_ALIGNED (static_struct1_alignas); - CHECK_ALIGNED (static_struct1_Alignas); CHECK_ALIGNED (static_struct2_alignas); - CHECK_ALIGNED (static_struct2_Alignas); CHECK_ALIGNED (static_struct3_alignas); - CHECK_ALIGNED (static_struct3_Alignas); CHECK_ALIGNED (static_struct4_alignas); - CHECK_ALIGNED (static_struct4_Alignas); return 0; #endif } -- 2.37.2