From cb8059d2d399a2db5f3de1e911b5b9947d6c7339 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 1 Jan 2011 21:37:21 -0500 Subject: [PATCH] Fix compilation on Windows with NDEBUG Dongsheng Song reports that when building on windows with NDEBUG, you run into an attempt to do EVUTIL_ASSERT(x) where x is a bitfield, which turns into _EVUTIL_NIL_CONDITION(x), which takes sizeof(x), which is illegal. This patch fixes _EVUTIL_NIL_CONDITION to work on bitfields too. --- util-internal.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util-internal.h b/util-internal.h index cb76ee4f..5c153d30 100644 --- a/util-internal.h +++ b/util-internal.h @@ -52,9 +52,13 @@ extern "C" { /* A good no-op to use in macro definitions. */ #define _EVUTIL_NIL_STMT ((void)0) -/* Suppresses the compiler's "unused variable" warnings for unused assert. */ +/* A no-op that tricks the compiler into thinking a condition is used while + * definitely not making any code for it. Used to compile out asserts while + * avoiding "unused variable" warnings. The "!" forces the compiler to + * do the sizeof() on an int, in case "condition" is a bitfield value. + */ #define _EVUTIL_NIL_CONDITION(condition) do { \ - (void)sizeof(condition); \ + (void)sizeof(!(condition)); \ } while(0) /* Internal use only: macros to match patterns of error codes in a