On November 23, 2018 2:58:44 PM EST, Emil Dotchevski via Boost
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() )
Why is that the appropriate cast? If your argument is that such a cast is the likely change applied by an ignorant maintainer trying to silence a warning, then that's not a good argument. An ignorant maintainer can make all sorts of breaking changes.
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.
Your point that a cast may not be the best solution to eliminating warnings is valid. Assertions, range checking, or library solutions are necessary to know that operations are safe. With those in place, pragmas and casts can be used to silence warnings. You may argue that the implicit conversion is correct, but it is as much subject to breakage by future maintenance as your example. -- Rob (Sent from my portable computation device.)