Mercurial > hg > octave-nkf > gnulib-hg
annotate m4/stdalign.m4 @ 17375:7524d97ae56f
stdalign: port to stricter ISO C11
ISO C11 says that _Alignof's operand must be a parenthesized type.
Problem reported by Eli Zaretskii in
<http://lists.gnu.org/archive/html/emacs-devel/2013-03/msg00960.html>.
* doc/posix-headers/stdalign.texi (stdalign.h): Document this.
* m4/stdalign.m4 (gl_STDALIGN_H): Don't use _Alignof (expr).
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 29 Mar 2013 19:47:13 -0700 |
parents | e542fd46ad6f |
children | 6b7c1e9c98d6 |
rev | line source |
---|---|
16239
91f53c1e1787
doc: C11 and C++11 are now official
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
1 # Check for stdalign.h that conforms to C11. |
15994 | 2 |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16321
diff
changeset
|
3 dnl Copyright 2011-2013 Free Software Foundation, Inc. |
15994 | 4 dnl This file is free software; the Free Software Foundation |
5 dnl gives unlimited permission to copy and/or distribute it, | |
6 dnl with or without modifications, as long as this notice is preserved. | |
7 | |
8 # Prepare for substituting <stdalign.h> if it is not supported. | |
9 | |
10 AC_DEFUN([gl_STDALIGN_H], | |
11 [ | |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
12 AC_CACHE_CHECK([for working stdalign.h], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
13 [gl_cv_header_working_stdalign_h], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
14 [AC_COMPILE_IFELSE( |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
15 [AC_LANG_PROGRAM( |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
16 [[#include <stdalign.h> |
16318
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
17 #include <stddef.h> |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
18 |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
19 /* Test that alignof yields a result consistent with offsetof. |
16319
934a441c5452
Fix bug# typo in previous patch.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16318
diff
changeset
|
20 This catches GCC bug 52023 |
934a441c5452
Fix bug# typo in previous patch.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16318
diff
changeset
|
21 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */ |
16318
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
22 #ifdef __cplusplus |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
23 template <class t> struct alignof_helper { char a; t b; }; |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
24 # define ao(type) offsetof (alignof_helper<type>, b) |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
25 #else |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
26 # define ao(type) offsetof (struct { char a; type b; }, b) |
39ff0ed6c426
stdalign: check that alignof and offsetof are consistent
Paul Eggert <eggert@cs.ucla.edu>
parents:
16239
diff
changeset
|
27 #endif |
16321
1031e29cf9ff
stdalign: relax _Alignof and tighten _Alignas test
Paul Eggert <eggert@cs.ucla.edu>
parents:
16319
diff
changeset
|
28 char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1]; |
1031e29cf9ff
stdalign: relax _Alignof and tighten _Alignas test
Paul Eggert <eggert@cs.ucla.edu>
parents:
16319
diff
changeset
|
29 char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1]; |
1031e29cf9ff
stdalign: relax _Alignof and tighten _Alignas test
Paul Eggert <eggert@cs.ucla.edu>
parents:
16319
diff
changeset
|
30 char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1]; |
15994 | 31 |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
32 /* Test _Alignas only on platforms where gnulib can help. */ |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
33 #if \ |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
34 (__GNUC__ || __IBMC__ || __IBMCPP__ \ |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
35 || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER) |
17375
7524d97ae56f
stdalign: port to stricter ISO C11
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
36 struct alignas_test { char c; char alignas (8) alignas_8; }; |
7524d97ae56f
stdalign: port to stricter ISO C11
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
37 char test_alignas[offsetof (struct alignas_test, alignas_8) == 8 |
7524d97ae56f
stdalign: port to stricter ISO C11
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
38 ? 1 : -1]; |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
39 #endif |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
40 ]])], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
41 [gl_cv_header_working_stdalign_h=yes], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
42 [gl_cv_header_working_stdalign_h=no])]) |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
43 |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
44 if test $gl_cv_header_working_stdalign_h = yes; then |
15994 | 45 STDALIGN_H='' |
46 else | |
47 STDALIGN_H='stdalign.h' | |
48 fi | |
49 | |
50 AC_SUBST([STDALIGN_H]) | |
51 AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"]) | |
52 ]) |