[cfe-commits] Support <x>-to-bool warnings for more contexts

Matt Beaumont-Gay matthewbg at google.com
Tue Apr 3 09:42:42 PDT 2012

On Mon, Apr 2, 2012 at 18:03, David Blaikie <dblaikie at gmail.com> wrote:
> Another thing I noticed as I was exploring this. We have a warning for
> float-literal-to-int such as:
> conv.cpp:2:9: warning: implicit conversion turns literal
> floating-point number into integer: 'double' to 'int'
> [-Wliteral-conversion]
> int i = 3.1415;
>    ~   ^~~~~~
> But this warning is off-by-default. Why is that?

Historical accident? I didn't even remember that it was off by
default. I say flip the switch to turn it on.

> It's already
> relatively conservative (allowing things like : "int i = 3.0" because
> 3.0 converts to an int without loss of precision) - though it's not a
> DiagnoseRuntimeBehavior, which it could be changed to (to be
> consistent with similar things for integers like "unsigned char c =
> 256").
> Or is it really that common to deliberately use floating point
> literals to initialize integer values?

Well, the "int kNumMicrosPerSecond = 1e6" case is very common, but the
warning is suppressed in that case. (Actually, that may be one reason
the warning is off by default -- the first implementation didn't have
such suppression.)


More information about the cfe-commits mailing list