tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: static_assert



How is this for a proposed patch?



Provide a fallback definition for _Static_assert for when the compiler
doesn't provide it (it doesn't have to for pre-C11).

Fixes https://rt.perl.org/Public/Bug/Display.html?id=134023

Index: cdefs.h
===================================================================
RCS file: /cvsroot/src/sys/sys/cdefs.h,v
retrieving revision 1.141
diff -u -r1.141 cdefs.h
--- cdefs.h	21 Feb 2019 21:34:05 -0000	1.141
+++ cdefs.h	22 May 2019 18:39:41 -0000
@@ -158,6 +158,14 @@
 #define	__CTASSERT1(x, y, z)	typedef char y ## z[/*CONSTCOND*/(x) ? 1 : -1] __unused
 
 /*
+ * Fallback definition to _Static_assert, part of C11,
+ * normally provided by the compiler.
+ */
+#if (__STDC_VERSION__ - 0 < 201101L)
+#define _Static_assert(expr, message)	__CTASSERT(expr)
+#endif
+
+/*
  * The following macro is used to remove const cast-away warnings
  * from gcc -Wcast-qual; it should be used with caution because it
  * can hide valid errors; in particular most valid uses are in



Home | Main Index | Thread Index | Old Index