]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add ersatz _Static_assert on older C hosts
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 5 Feb 2015 23:52:20 +0000 (15:52 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 7 Feb 2015 22:43:27 +0000 (14:43 -0800)
* misc/sys/cdefs.h (_Static_assert): Define a substitute, if on a
pre-C11 C platform that is not known to support _Static_assert.

ChangeLog
assert/assert.h
misc/sys/cdefs.h

index ade23843ac6b88a7d342a3b4fb5e0e54285c0407..4584975f3e52b63e3812cde1a2e1fb5cac53d2dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Add ersatz _Static_assert on older C hosts
+       * misc/sys/cdefs.h (_Static_assert): Define a substitute, if on a
+       pre-C11 C platform that is not known to support _Static_assert.
+
 2015-02-07  Richard Braun  <rbraun@sceen.net>
 
        * hurd/hurd/signal.h (_hurd_critical_section_lock): Don't unlock
index ae777931c5fd275b028bd7f85e5a9b1bae396096..d04c58cc8a664ec1e568b358a2973395ea8e1192 100644 (file)
@@ -113,7 +113,6 @@ __END_DECLS
 
 
 #if defined __USE_ISOC11 && !defined __cplusplus
-/* Static assertion.  Requires support in the compiler.  */
 # undef static_assert
 # define static_assert _Static_assert
 #endif
index 09ee352e1ff30ea0cb49e2c4e3b536f7c5e3dfa0..99e94cce869572b724df6b5b8c847cc38a0b3a57 100644 (file)
 # endif
 #endif
 
+#if (!defined _Static_assert && !defined __cplusplus \
+     && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
+     && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
+# define _Static_assert(expr, diagnostic) \
+    extern int (*__Static_assert_function (void)) \
+      [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
+#endif
+
 #include <bits/wordsize.h>
 
 #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH