newlib: change definition of assert for release builds

One common pattern of using assert function looks as follows:
    int ret = do_foo();
    assert(ret == 0);   // which reads as: “do_foo should never fail here, by design”
The problem with such code is that if ‘assert’ is removed by the preprocessor in release build,
variable ret is no longer used, and the compiler issues a warning about this.
Changing assert definition in the way done here make the variable used, from language syntax perspective.
Semantically, the variable is still unused at run time (as sizeof can be evaluated at compile time), so the compiler
can optimize things away if possible.
This commit is contained in:
Ivan Grokhotkov 2017-01-17 00:49:38 +08:00
parent 075446318d
commit c47cc63489
2 changed files with 4 additions and 2 deletions

View file

@ -11,7 +11,7 @@ extern "C" {
#undef assert
#ifdef NDEBUG /* required by ANSI standard */
# define assert(__e) ((void)0)
# define assert(__e) ((void) sizeof(__e))
#else
# define assert(__e) ((__e) ? (void)0 : __assert_func (__FILE__, __LINE__, \
__ASSERT_FUNC, #__e))

View file

@ -163,8 +163,10 @@ esp_err_t PageManager::requestNewPage()
return err;
}
#ifndef NDEBUG
assert(usedEntries == newPage->getUsedEntryCount());
#endif
mPageList.erase(maxErasedItemsPageIt);
mFreePageList.push_back(erasedPage);