* [PATCH] stdalign-tests: port to C23
@ 2022-09-13 17:59 Paul Eggert
2022-09-13 20:19 ` Bruno Haible
0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2022-09-13 17:59 UTC (permalink / raw
To: bug-gnulib; +Cc: Paul Eggert
* 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 ++++++++
| 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 <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.
--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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] stdalign-tests: port to C23
2022-09-13 17:59 [PATCH] stdalign-tests: port to C23 Paul Eggert
@ 2022-09-13 20:19 ` Bruno Haible
2022-09-13 21:04 ` Paul Eggert
0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2022-09-13 20:19 UTC (permalink / raw
To: bug-gnulib, Paul Eggert
Paul Eggert wrote:
> _Alignof, or _Alignas as they are obsolescent.
_Alignas is obsolescent? Then we should better talk about 'alignas' instead.
2022-09-13 Bruno Haible <bruno@clisp.org>
Prefer talking about alignas than _Alignas.
* m4/gnulib-common.m4 (gl_COMMON_BODY): Don't mention _Alignas in a
comment.
* m4/stdalign.m4 (gl_STDALIGN_H): Likewise.
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 8a5daa230e..d17cbec58c 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 73
+# gnulib-common.m4 serial 74
dnl Copyright (C) 2007-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -115,7 +115,7 @@ AC_DEFUN([gl_COMMON_BODY], [
# define _GL_HAS_C_ATTRIBUTE(attr) 0
#endif
-]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's _Alignas instead.
+]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
[
/* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
is the size of the returned memory block.
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index 78577cb2ac..c3283760d5 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -30,7 +30,7 @@ AC_DEFUN([gl_STDALIGN_H],
char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];
- /* Test _Alignas only on platforms where gnulib can help. */
+ /* Test alignas only on platforms where gnulib can help. */
#if \
((defined __cplusplus && 201103 <= __cplusplus) \
|| (__TINYC__ && defined __attribute__) \
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] stdalign-tests: port to C23
2022-09-13 20:19 ` Bruno Haible
@ 2022-09-13 21:04 ` Paul Eggert
0 siblings, 0 replies; 3+ messages in thread
From: Paul Eggert @ 2022-09-13 21:04 UTC (permalink / raw
To: Bruno Haible, bug-gnulib
On 9/13/22 15:19, Bruno Haible wrote:
> _Alignas is obsolescent?
Although it's still in the standard as of draft C23, it is to some
extent deprecated as it is no longer necessarily a keyword (it might be
a macro). My guess is that it will be obsoleted in some future version
of the standard, if they keep producing new standards. As it's an
unnecessary appendage at this point I think it's safe to call it
obsolescent.
Similarly for other former keywords like _Bool and _Static_assert.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-13 21:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-13 17:59 [PATCH] stdalign-tests: port to C23 Paul Eggert
2022-09-13 20:19 ` Bruno Haible
2022-09-13 21:04 ` Paul Eggert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).