[PATCH 21.5] ALIGNOF with C11/C++11

Jerry James <[email protected]> Fri, 17 Apr 2015 14:48:16 -0600
Newsgroups gmane.emacs.xemacs.patches
Message-ID <CAHCOHQmG51R61KwGUNY7T5t9tXxzbyg=aGijUKYstbE+wL2-6Q@mail.gmail.com>
PATCH 21.5

Using gcc 5.0, the build fails with both -std=c11 and -std=c++11,
because of a clash on the name max_align_t.  But we don't need to
define max_align_t in those 2 cases, because the languages themselves
now define operators that can be used for ALIGNOF, as in this patch.

diff -r 8704b7957585 src/ChangeLog
--- a/src/ChangeLog Sat Apr 11 18:34:14 2015 +0100
+++ b/src/ChangeLog Fri Apr 17 14:46:54 2015 -0600
@@ -1,3 +1,9 @@
+2015-04-17  Jerry James  <[email protected]>
+
+ * lisp.h (max_align_t): Do not define if C11 or C++11, or a later
+ version of either, is in use.
+ (ALIGNOF): Define with native operators in C11 and C++11.
+
 2015-04-09  Aidan Kehoe  <[email protected]>

  * tls.c (nss_pk11_password):
diff -r 8704b7957585 src/lisp.h
--- a/src/lisp.h Sat Apr 11 18:34:14 2015 +0100
+++ b/src/lisp.h Fri Apr 17 14:46:54 2015 -0600
@@ -1154,6 +1154,8 @@

 /* ------------------------ alignment definitions ------------------- */

+#if (defined (__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
+    (defined (__cplusplus) && __cplusplus < 201103L)
 /* No type has a greater alignment requirement than max_align_t.
    (except perhaps for types we don't use, like long double) */
 typedef union
@@ -1163,6 +1165,7 @@
   struct { void (*f)(void); } f;
   struct { double d; } d;
 } max_align_t;
+#endif

 /* ALIGNOF returns the required alignment of a type -- i.e. a value such
    that data of this type must begin at a memory address which is a
@@ -1170,7 +1173,11 @@
    as the type itself. */

 #ifndef ALIGNOF
-# if defined (__GNUC__) && (__GNUC__ >= 2)
+# if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#  define ALIGNOF(type) _Alignof(type)
+# elif defined (__cplusplus) && __cplusplus >= 201103L
+#  define ALIGNOF(type) alignof(type)
+# elif defined (__GNUC__) && (__GNUC__ >= 2)
 /* gcc has an extension that gives us exactly what we want. */
 #  define ALIGNOF(type) __alignof__ (type)
 # elif ! defined (__cplusplus)

-- 
Jerry James
http://www.jamezone.org/