From 76b5e93f73836fcfd76ae7485c3463d5c046c3a8 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 23 Nov 2021 16:22:51 -0500 Subject: [PATCH] Fix #51, do not assert when NDEBUG is set This effectively ignores CF_Assert checks in the code when it is compiled with NDEBUG. None of these checks should be needed after development. In particular, this removes the use of the non-standard "unlikely" compiler extension that was used here. --- fsw/src/cf_assert.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fsw/src/cf_assert.h b/fsw/src/cf_assert.h index 32ad7bcd..1c39362c 100644 --- a/fsw/src/cf_assert.h +++ b/fsw/src/cf_assert.h @@ -31,11 +31,23 @@ extern void CF_HandleAssert(const char *file, int line); +/* + * Note that in some cases, code in CF may compute or store a value for the + * sole purpose of checking it with a CF_Assert(). If CF_Assert is then entirely + * compiled out with NDEBUG, the compiler may see that as an unused value and + * trigger a warning. + * + * To avoid this, a no-op inline function is used, such that the value in the + * CF_Assert call is still evaluated, but the result is ignored. + */ + #ifdef NDEBUG /* this is release mode */ -#define CF_Assert(x) \ - if (unlikely((x))) \ - CF_HandleAssert(__FILE__, __LINE__); +static inline void CF_NoAssert(bool cond) +{ + /* no-op to avoid unused value warning */ +} +#define CF_Assert(x) CF_NoAssert(x) #else /* NDEBUG */ #include #define CF_Assert(x) assert(x)