From f39011b8b6a25f8399daa9e6893bbf58872fb657 Mon Sep 17 00:00:00 2001 From: Florian Krohm Date: Sat, 28 Mar 2015 18:36:01 +0000 Subject: [PATCH] Add STATIC_ASSERT and use it. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15047 --- include/pub_tool_basics.h | 3 +++ memcheck/tests/vbit-test/irops.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/pub_tool_basics.h b/include/pub_tool_basics.h index b9bdbc7849..5c34fe706f 100644 --- a/include/pub_tool_basics.h +++ b/include/pub_tool_basics.h @@ -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 */ /*--------------------------------------------------------------------*/ diff --git a/memcheck/tests/vbit-test/irops.c b/memcheck/tests/vbit-test/irops.c index aff701cd91..f442212503 100644 --- a/memcheck/tests/vbit-test/irops.c +++ b/memcheck/tests/vbit-test/irops.c @@ -2,6 +2,7 @@ #include // fprintf #include // 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. */ -- 2.47.3