
AMDG Roland Bock wrote:
DE wrote:
there were a discussion recentrly about verifying arguments of assertion macros while checks are turned off
I guess this would be closer to what you want:
// ------------------------------------------ #include <cassert> #ifdef NDEBUG #ifdef assert #undef assert static bool assert_helper(const bool&) { return true; } #define assert(cond) if (sizeof(assert_helper(cond))) {} #endif #endif // ------------------------------------------
The following compiles without warning, regardless of NDEBUG being defined or not (I used g++ test.cpp -Wall -Wextra -O3):
// -------------------- int main() { int i = 0; assert(i); } // --------------------
MSVC 9.0 /W4 .\scratch.cpp(14) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) .\scratch.cpp(14) : warning C4127: conditional expression is constant .\scratch.cpp(7) : warning C4505: 'assert_helper' : unreferenced local function has been removed In Christ, Steven Watanabe