+2022-09-13 Paul Eggert <eggert@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 <bruno@clisp.org>
supersede: Avoid a failure when writing to /dev/null in Solaris zones.
@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
@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
/* 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
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
#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)
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
}