]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add STATIC_ASSERT and use it.
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 28 Mar 2015 18:36:01 +0000 (18:36 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 28 Mar 2015 18:36:01 +0000 (18:36 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15047

include/pub_tool_basics.h
memcheck/tests/vbit-test/irops.c

index b9bdbc78493f73925daadb73aff9585504de4552..5c34fe706fc42ecb3cf7474c3edc518713529edf 100644 (file)
@@ -367,6 +367,9 @@ static inline Bool sr_EQ ( SysRes sr1, SysRes sr2 ) {
       } var = { .in = x }; var.out;  \
    })
 
+// Poor man's static assert
+#define STATIC_ASSERT(x)  extern int VG_(VG_(VG_(unused)))[(x) ? 1 : -1]
+
 #endif /* __PUB_TOOL_BASICS_H */
 
 /*--------------------------------------------------------------------*/
index aff701cd91fe83acfed4e5d2cee0f293c2e69426..f442212503dfbb37310654c07df0ee8dd4e40367 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <stdio.h>    // fprintf
 #include <stdlib.h>   // exit
+#include "pub_tool_basics.h"   // STATIC_ASSERT
 #include "vtest.h"
 
 #define DEFOP(op,ukind) op, #op, ukind
@@ -1050,9 +1051,8 @@ static irop_t irops[] = {
 
 /* Force compile time failure in case libvex_ir.h::IROp was updated
    and the irops array is out of synch */
-extern int ensure_complete[
-   (sizeof irops / sizeof *irops == Iop_LAST - Iop_INVALID - 1) ? 1 : -1
-                          ];
+STATIC_ASSERT \
+      (sizeof irops / sizeof *irops == Iop_LAST - Iop_INVALID - 1);
 
 /* Return a descriptor for OP, iff it exists and it is implemented
    for the current architecture. */