On Mon, Apr 2, 2012 at 18:03, David Blaikie <[email protected]> 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.) -Matt _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
