Mercurial > hg > octave-nkf > gnulib-hg
annotate m4/stdalign.m4 @ 17445:6b7c1e9c98d6
stdalign, verify: port to FreeBSD 9.1, to C11, and to C++11
Problem reported by Ulrich Mueller in <http://bugs.gnu.org/14812>.
* lib/stdalign.in.h (_Alignas, _Alignof):
Port to FreeBSD 9.1, and to C11 and C++11.
(_Alignas): Also support ICC.
* lib/verify.h (_Static_assert): Undef if <stddef.h> defines it.
* m4/stdalign.m4 (gl_STDALIGN_H): Port to ICC and to C++11.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 07 Jul 2013 23:06:26 -0700 |
parents | 7524d97ae56f |
children | 344018b6e5d7 |
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 \ |
17445
6b7c1e9c98d6
stdalign, verify: port to FreeBSD 9.1, to C11, and to C++11
Paul Eggert <eggert@cs.ucla.edu>
parents:
17375
diff
changeset
|
34 ((defined __cplusplus && 201103 <= __cplusplus) \ |
6b7c1e9c98d6
stdalign, verify: port to FreeBSD 9.1, to C11, and to C++11
Paul Eggert <eggert@cs.ucla.edu>
parents:
17375
diff
changeset
|
35 || __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC \ |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
36 || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER) |
17375
7524d97ae56f
stdalign: port to stricter ISO C11
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
37 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
|
38 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
|
39 ? 1 : -1]; |
16140
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
40 #endif |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
41 ]])], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
42 [gl_cv_header_working_stdalign_h=yes], |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
43 [gl_cv_header_working_stdalign_h=no])]) |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
44 |
7fae013a2fd6
stdalign: port to Clang 3.0
Paul Eggert <eggert@cs.ucla.edu>
parents:
15999
diff
changeset
|
45 if test $gl_cv_header_working_stdalign_h = yes; then |
15994 | 46 STDALIGN_H='' |
47 else | |
48 STDALIGN_H='stdalign.h' | |
49 fi | |
50 | |
51 AC_SUBST([STDALIGN_H]) | |
52 AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"]) | |
53 ]) |