On Thu, Nov 22, 2018 at 12:56 AM Jayesh Badwaik via Boost < boost@lists.boost.org> wrote:
On Monday, 19 November 2018 21:02:55 CET Emil Dotchevski via Boost wrote:
In that context there are probably legal reason for zero-warning policy, but it is not true that lack of warnings means fewer errors, in fact it could easily lead to more errors. For example warnings about implicit conversions are frequently "fixed" by replacing the implicit conversion with explicit conversion (cast). But the two are semantically very different, and therefore one of them is incorrect, and very likely that
is
the explicit one.
Didn't know that. Can I see an example where the explicit warning is incorrect as opposed to implicit warning?
I'm guessing you want an example where the explicit conversion is incorrect, and you want to use an implicit conversion even though you get a warning. Here: unsigned f(); void g( int x ) { if( x < f() ) //warning C4018: '<': signed/unsigned mismatch { .... } } So you change that to: if( static_cast<unsigned>(x) < f() ) Then under refactoring both f and g get changed: unsigned long f(); void g( long x ) { if( static_cast<unsigned>(x) < f() ) { .... } } And now you probably have a bug, and no warning. I say probably, because if this was my code, I'd know the cast is correct because my choice of implicit vs. explicit conversion does not depend on what warnings I get from the compiler, I do what is right. But if you've instructed your programmers to use casts to silence warnings, you never know why that cast sits there. Assuming the implicit conversion is correct (it probably is, but you should always know), this should be written as: assert(x>=0); if( x < f() )