Building a testdir on AIX 7.2 with xlc, I get this compilation error:
xlc -qthreaded -qtls -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I.
-I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I.
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib
-I/home/haible/prefix32/include -D_THREAD_SAFE -g -c -o test-alignasof.o
../../gltests/test-alignasof.c
"../../gltests/test-alignasof.c", line 51.1: 1506-275 (S) Unexpected text
integer constant encountered.
"../../gltests/test-alignasof.c", line 51.1: 1506-276 (S) Syntax error:
possible missing '{'?
"../../gltests/test-alignasof.c", line 52.1: 1506-273 (E) Missing type in
declaration of short_helper.
"../../gltests/test-alignasof.c", line 52.1: 1506-046 (S) Syntax error.
"../../gltests/test-alignasof.c", line 52.1: 1506-122 (S) Expecting pointer to
struct or union.
"../../gltests/test-alignasof.c", line 52.1: 1506-275 (S) Unexpected text
integer constant encountered.
"../../gltests/test-alignasof.c", line 52.1: 1506-343 (S) Redeclaration of
_Alignas differs from previous declaration on line 51 of
"../../gltests/test-alignasof.c".
"../../gltests/test-alignasof.c", line 52.1: 1506-050 (I) Return type "short"
in redeclaration is not compatible with the previous return type "char".
"../../gltests/test-alignasof.c", line 52.1: 1506-276 (S) Syntax error:
possible missing '{'?
"../../gltests/test-alignasof.c", line 53.1: 1506-273 (E) Missing type in
declaration of int_helper.
"../../gltests/test-alignasof.c", line 53.1: 1506-046 (S) Syntax error.
"../../gltests/test-alignasof.c", line 53.1: 1506-122 (S) Expecting pointer to
struct or union.
"../../gltests/test-alignasof.c", line 53.1: 1506-275 (S) Unexpected text
integer constant encountered.
"../../gltests/test-alignasof.c", line 53.1: 1506-276 (S) Syntax error:
possible missing '{'?
"../../gltests/test-alignasof.c", line 54.1: 1506-273 (E) Missing type in
declaration of long_helper.
"../../gltests/test-alignasof.c", line 54.1: 1506-046 (S) Syntax error.
"../../gltests/test-alignasof.c", line 54.1: 1506-122 (S) Expecting pointer to
struct or union.
"../../gltests/test-alignasof.c", line 54.1: 1506-275 (S) Unexpected text
integer constant encountered.
"../../gltests/test-alignasof.c", line 54.1: 1506-276 (S) Syntax error:
possible missing '{'?
"../../gltests/test-alignasof.c", line 56.1: 1506-273 (E) Missing type in
declaration of int64_t_helper.
"../../gltests/test-alignasof.c", line 56.1: 1506-046 (S) Syntax error.
"../../gltests/test-alignasof.c", line 56.1: 1506-122 (S) Expecting pointer to
struct or union.
"../../gltests/test-alignasof.c", line 56.1: 1506-275 (S) Unexpected text
integer constant encountered.
"../../gltests/test-alignasof.c", line 56.1: 1506-276 (S) Syntax error:
possible missing '{'?
"../../gltests/test-alignasof.c", line 58.1: 1506-273 (E) Missing type in
declaration of float_helper.
"../../gltests/test-alignasof.c", line 58.1: 1506-046 (S) Syntax error.
"../../gltests/test-alignasof.c", line 58.1: 1506-122 (S) Expecting pointer to
struct or union.
Makefile:24036: recipe for target 'test-alignasof.o' failed
The cause is that the compiler does not have an _Alignas built-in, nor is
there an _Alignas macro. config.h includes <stdalign.h> (which happens to
be /usr/include/stdalign.h), but this header file basically only defines
#define alignas _Alignas
#define alignof _Alignof
Since _Alignas is a normal identifier at this point, the syntax errors are
normal.
It is wrong to assume that <stdalign.h> will define _Alignas:
- ISO C 11 specifies that <stdalign.h> defines alignas, alignof,
__alignas_is_defined, __alignof_is_defined, and nothing else.
- GCC's and clang's private <stdalign.h> do the same: They don't define
_Alignas either.
So, the fix is to define _Alignas also when HAVE_STDALIGN_H is 1.
The definition with __attribute__((aligned(n))) is fine for xlc, per the
documentation at
https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=data-using-alignment-modifiers
2023-04-10 Bruno Haible <[email protected]>
alignasof: Ensure a correct _Alignas (regression 2023-01-15).
* m4/stdalign.m4 (gl_ALIGNASOF): Define _Alignas also when <stdalign.h>
exists.
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index f49cf8ec16..1a236d66d2 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -151,22 +151,22 @@ AC_DEFUN([gl_ALIGNASOF]
- alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
*/
-# if !HAVE_STDALIGN_H
-# if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
-# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)
-# define _Alignas(a) alignas (a)
-# elif (!defined __attribute__ \
- && ((defined __APPLE__ && defined __MACH__ \
- ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
- : __GNUC__ && !defined __ibmxl__) \
- || (4 <= __clang_major__) \
- || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
- || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
-# define _Alignas(a) __attribute__ ((__aligned__ (a)))
-# elif 1300 <= _MSC_VER
-# define _Alignas(a) __declspec (align (a))
-# endif
+# if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
+# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)
+# define _Alignas(a) alignas (a)
+# elif (!defined __attribute__ \
+ && ((defined __APPLE__ && defined __MACH__ \
+ ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
+ : __GNUC__ && !defined __ibmxl__) \
+ || (4 <= __clang_major__) \
+ || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
+ || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
+# define _Alignas(a) __attribute__ ((__aligned__ (a)))
+# elif 1300 <= _MSC_VER
+# define _Alignas(a) __declspec (align (a))
# endif
+# endif
+# if !HAVE_STDALIGN_H
# if ((defined _Alignas \
&& !(defined __cplusplus \
&& (201103 <= __cplusplus || defined _MSC_VER))) \