
AMDG Paul A. Bristow wrote:
Guidelines
I've tried to distill the many helpful comments on this as follows:
||C4800|| int' : forcing value to bool 'true' or 'false'||
Use a bool valued expression.
Write out expressions, for example: "value >= 0" or "ptr != 0" (Boost prefers clarity to curtness). Take care if using templates that constants are of the right type, for example you may need "static_cast<T>(1)". Or use static_cast<bool>(expression). Or suppress.
||# pragma warning(disable: 4800) // int' : forcing value to bool 'true' or 'false'
Hope this is better.
I note that this will mean quite a lot of work for some people as "if (ptr) ..." is such a common (and IMO dreadful) idiom.
So I've left the getout clause "suppress" as a last resort.
But this might encourage people to write new code in a nicer way.
I think the most common cause of this warning is that std::type_info::before (which is supposed to return bool) returns int instead. Also, static_cast<bool> doesn't suppress the warning. In Christ, Steven Watanabe