On 2023-01-14 17:20, Khem Raj wrote:
+/* GCC releases before GCC 4.9 had a bug in _Alignof.  See GCC bug 52023
+<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
+   clang versions < 8.0.0 have the same bug.  */
+#elif (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
+       || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
+           && !defined __clang__) \
+       || (defined __clang__ && __clang_major__ < 8))

We already have two copies of that stuff elsewhere (in lib/stdalign.in.h and m4/stdalign.m4), for reasons that currently escape me. Let's not balloon the number of copies to three.

I installed the attached smaller patch which should do the trick for C.

Is there a similar problem with C++.
From 2d404c7dd974cc65f894526f4a1b76bc1dcd8d82 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 14 Jan 2023 17:48:18 -0800
Subject: [PATCH] alignof: port to strict C23

Problem reported by Khem Raj in:
https://lists.gnu.org/r/bug-gnulib/2023-01/msg00111.html
* lib/alignof.h (alignof_slot) [!__cplusplus]: Use C23-style alignof.
* modules/alignof (Depends-on): Add stdalign.
---
 ChangeLog       | 6 ++++++
 lib/alignof.h   | 4 ++--
 modules/alignof | 1 +
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0900c54c1d..fa684131db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-01-14  Paul Eggert  <egg...@cs.ucla.edu>
 
+	alignof: port to strict C23
+	Problem reported by Khem Raj in:
+	https://lists.gnu.org/r/bug-gnulib/2023-01/msg00111.html
+	* lib/alignof.h (alignof_slot) [!__cplusplus]: Use C23-style alignof.
+	* modules/alignof (Depends-on): Add stdalign.
+
 	test-framework-sh: work around AIX 7.2 diff bugs
 	* tests/init.sh (compare_dev_null_): Run diff in the C locale.
 	AIX 7.2 diff messes up in UTF-8 locales; for example,
diff --git a/lib/alignof.h b/lib/alignof.h
index 505ad97aa4..2ded1c7884 100644
--- a/lib/alignof.h
+++ b/lib/alignof.h
@@ -22,14 +22,14 @@
 /* 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).
+   This is the same as 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
   template <class type> struct alignof_helper { char __slot1; type __slot2; };
 # define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
 #else
-# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
+# define alignof_slot(type) alignof (type)
 #endif
 
 /* alignof_type (TYPE)
diff --git a/modules/alignof b/modules/alignof
index 4345eaca12..c78ab4a3c5 100644
--- a/modules/alignof
+++ b/modules/alignof
@@ -5,6 +5,7 @@ Files:
 lib/alignof.h
 
 Depends-on:
+stdalign
 
 configure.ac:
 
-- 
2.37.2

Reply via email to