From b63ab1776b3bbf3fe47406d0ca9639b299c4348d Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Mon, 6 Dec 2010 14:17:44 -0500 Subject: [PATCH] EVUTIL_ASSERT: Use sizeof() to avoid "unused variable" warnings. --- buffer.c | 6 ++++++ util-internal.h | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/buffer.c b/buffer.c index bf53fae6..50908b19 100644 --- a/buffer.c +++ b/buffer.c @@ -246,6 +246,12 @@ evbuffer_chains_all_empty(struct evbuffer_chain *chain) } return 1; } +#else +/* The definition is needed for EVUTIL_ASSERT, which uses sizeof to avoid +"unused variable" warnings. */ +static inline int evbuffer_chains_all_empty(struct evbuffer_chain *chain) { + return 1; +} #endif static void diff --git a/util-internal.h b/util-internal.h index 73cd8f8c..cb76ee4f 100644 --- a/util-internal.h +++ b/util-internal.h @@ -52,6 +52,10 @@ 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. */ +#define _EVUTIL_NIL_CONDITION(condition) do { \ + (void)sizeof(condition); \ +} while(0) /* Internal use only: macros to match patterns of error codes in a cross-platform way. We need these macros because of two historical @@ -177,7 +181,7 @@ long _evutil_weakrand(void); /* Replacement for assert() that calls event_errx on failure. */ #ifdef NDEBUG -#define EVUTIL_ASSERT(cond) _EVUTIL_NIL_STMT +#define EVUTIL_ASSERT(cond) _EVUTIL_NIL_CONDITION(cond) #define EVUTIL_FAILURE_CHECK(cond) 0 #else #define EVUTIL_ASSERT(cond) \ -- 2.40.0