
Peter Dimov wrote:
Steven Watanabe:
AMDG
Roland Bock wrote:
Stewart, Robert wrote:
C4800 seems ridiculous. Writing code using int as a Boolean is common to C code. Why would VC 9 inflict useless noise when compiling such code? Besides, if the variable is int, and it is needed in a Boolean context, what else would the developer do? I've seen use of the conditional operator to avoid that warning. I suspect that produces worse code than what is done when "forcing value to bool 'true' or 'false'."
I agree. Still, I hope that static_cast is allowed to remove C4800
Nope.
.\scratch.cpp(20) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
C4800 is avoided with expr? true: false. In this case, sizeof( expr? 0: 0 ) will also work, as we don't care about the value.
Oh! So the following should do the trick? That would be neat. It certainly works for gcc. #include <cassert> #ifdef NDEBUG #ifdef assert #undef assert #define assert(cond) static_cast<void>(sizeof(cond? 0: 0)); #endif #endif int main() { int i = 0; assert(i); }