You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
#defineETL_ASSERT(b, e) ETL_DO_NOTHING// Does nothing.
305
-
#defineETL_ASSERT_OR_RETURN(b, e) ETL_DO_NOTHING// Does nothing.
306
-
#defineETL_ASSERT_OR_RETURN_VALUE(b, e, v) ETL_DO_NOTHING// Does nothing.
304
+
#defineETL_ASSERT(b, e) static_cast<void>(sizeof(b))// Does nothing.
305
+
#defineETL_ASSERT_OR_RETURN(b, e) static_cast<void>(sizeof(b))// Does nothing.
306
+
#defineETL_ASSERT_OR_RETURN_VALUE(b, e, v) static_cast<void>(sizeof(b))// Does nothing.
307
307
308
-
#defineETL_ASSERT_FAIL(e) ETL_DO_NOTHING// Does nothing.
309
-
#defineETL_ASSERT_FAIL_AND_RETURN(e) ETL_DO_NOTHING// Does nothing.
310
-
#defineETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) ETL_DO_NOTHING// Does nothing.
308
+
#defineETL_ASSERT_FAIL(e) static_cast<void>(sizeof(b))// Does nothing.
309
+
#defineETL_ASSERT_FAIL_AND_RETURN(e) static_cast<void>(sizeof(b))// Does nothing.
310
+
#defineETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) static_cast<void>(sizeof(b))// Does nothing.
311
311
#elif defined(ETL_USE_ASSERT_FUNCTION)
312
312
#defineETL_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
313
313
#defineETL_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
353
353
#defineETL_ASSERT_FAIL_AND_RETURN(e) do {assert(false); return;} while(false) // Asserts.
354
354
#defineETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {assert(false); return(v);} while(false) // Asserts.
355
355
#else
356
-
#defineETL_ASSERT(b, e) ETL_DO_NOTHING // Does nothing.
356
+
#defineETL_ASSERT(b, e) static_cast<void>(sizeof(b))// Does nothing.
357
357
#defineETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY return;} while(false) // Returns.
358
358
#defineETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY return(v);} while(false) // Returns a value.
0 commit comments