<p dir="ltr">On Dec 30, 2015 6:34 AM, "Aaron Ballman" <<a href="mailto:aaron.ballman@gmail.com">aaron.ballman@gmail.com</a>> wrote:<br>
><br>
> aaron.ballman closed this revision.<br>
> aaron.ballman added a comment.<br>
><br>
> Thanks! I've commit in r256643.<br>
><br>
><br>
> ================<br>
> Comment at: test/SemaCXX/warn-literal-conversion.cpp:49-50<br>
> @@ +48,4 @@<br>
> +  // values.<br>
> +  bool b3 = 0.0f;<br>
> +  bool b4 = 0.0;<br>
> +}<br>
> ----------------<br>
> rsmith wrote:<br>
> > What about<br>
> ><br>
> >   bool b5 = 1.0;<br>
> >   bool b6 = 2.0;<br>
> ><br>
> > ? Arguably any `float` -> `bool` conversion changes the value (because `true` and `false` are not values of type `float`), so it wouldn't be completely unreasonable to warn even if the literal is `0.0`.<br>
> Except those conversions won't cause confusion to the user, so I'm not certain what we gain by diagnosing. Given that some mental models expect 0.99 to convert to 0, which converts to false (because bool is an integral type, so it "must" do the usual integral truncation dance), it makes sense to tell the user "no no no, that converts to true." I'm less convinced about the utility of warning on things like `bool b = 1.99f' where it changes the value from 1.99 to true. Perhaps this should be changed to only diagnose when converting through an integer would result in a different value that converting through the float?</p>
<p dir="ltr">Let me ask a slightly different question: when would it ever be reasonable and intentional to initialize a bool from a floating-point *literal*? For integers, people use things like</p>
<p dir="ltr">  int n = 1e6;</p>
<p dir="ltr">which is why we don't complain if the literal is exactly representable in the integer type. I can't imagine any similar cases for bool.</p>
<p dir="ltr">><br>
> <a href="http://reviews.llvm.org/D15814">http://reviews.llvm.org/D15814</a><br>
><br>
><br>
><br>
</p>