Skip to content

Commit 018c7ce

Browse files
christophruethingbmwJohn Wellbelovedenravonskajwellbelove
authored
Introduce Cast to void for Condition of Assert (#1191)
* Removed ETL_NOEXCEPT from delegate operator(), call_if(), and call_or() Removed ETL_NOEXCEPT from closureoperator(), call_if(), and call_or() * Updated version and release notes * Updated version and release notes * Remove noexcept from delegate method stubs. (#1185) In addition to removing noexcept from call_if, this is also needed to prevent an abort when cancelling a pthread that is executing a delegate. * Updated version and release notes * Introduce Cast to void for Condition of Assert Currently, in case we use a parameter of a function _only_ inside of an ETL_ASSERT and the ETL configuration disables the ETL_ASSERT, we get a compiler warning about an unused parameter. Therefore, this change casts the condition of ETL_ASSERT to void. * Use sizeof to avoid evaluation of Expression In case we disable ASSERTs in e.g. non debug builds, we want to expand it to "nothing", similar to how the std assert works. Introducing a cast to void on the conidition would still evaluate it and potentially cause side-effects. Therefore, we use the sizeof operator to ensure the expression is not evaluated in case ASSERTs are disabled. --------- Co-authored-by: John Wellbelove <[email protected]> Co-authored-by: Marco Nilsson <[email protected]> Co-authored-by: John Wellbelove <[email protected]>
1 parent 4cbc601 commit 018c7ce

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

include/etl/error_handler.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,13 @@ namespace etl
301301
///\ingroup error_handler
302302
//***************************************************************************
303303
#if defined(ETL_NO_CHECKS)
304-
#define ETL_ASSERT(b, e) ETL_DO_NOTHING // Does nothing.
305-
#define ETL_ASSERT_OR_RETURN(b, e) ETL_DO_NOTHING // Does nothing.
306-
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) ETL_DO_NOTHING // Does nothing.
304+
#define ETL_ASSERT(b, e) static_cast<void>(sizeof(b)) // Does nothing.
305+
#define ETL_ASSERT_OR_RETURN(b, e) static_cast<void>(sizeof(b)) // Does nothing.
306+
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) static_cast<void>(sizeof(b)) // Does nothing.
307307

308-
#define ETL_ASSERT_FAIL(e) ETL_DO_NOTHING // Does nothing.
309-
#define ETL_ASSERT_FAIL_AND_RETURN(e) ETL_DO_NOTHING // Does nothing.
310-
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) ETL_DO_NOTHING // Does nothing.
308+
#define ETL_ASSERT_FAIL(e) static_cast<void>(sizeof(b)) // Does nothing.
309+
#define ETL_ASSERT_FAIL_AND_RETURN(e) static_cast<void>(sizeof(b)) // Does nothing.
310+
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) static_cast<void>(sizeof(b)) // Does nothing.
311311
#elif defined(ETL_USE_ASSERT_FUNCTION)
312312
#define ETL_ASSERT(b, e) do {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));}} while(false) // If the condition fails, calls the assert function
313313
#define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;}} while(false) // If the condition fails, calls the assert function and return
@@ -353,7 +353,7 @@ namespace etl
353353
#define ETL_ASSERT_FAIL_AND_RETURN(e) do {assert(false); return;} while(false) // Asserts.
354354
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {assert(false); return(v);} while(false) // Asserts.
355355
#else
356-
#define ETL_ASSERT(b, e) ETL_DO_NOTHING // Does nothing.
356+
#define ETL_ASSERT(b, e) static_cast<void>(sizeof(b)) // Does nothing.
357357
#define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY return;} while(false) // Returns.
358358
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY return(v);} while(false) // Returns a value.
359359

0 commit comments

Comments
 (0)