On Wed, Feb 27, 2013 at 11:18 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, Feb 27, 2013 at 10:55 AM, Sean McBride <<a href="mailto:sean@rogue-research.com">sean@rogue-research.com</a>> wrote:<br>
> Hi all,<br>
><br>
> Consider this C++:<br>
><br>
> -------------------<br>
> #include <stdint.h><br>
><br>
> int main (void)<br>
> {<br>
> double d = 255.5;<br>
> uint8_t c = (uint8_t)d;<br>
><br>
> return c;<br>
> }<br>
> -------------------<br>
><br>
> then:<br>
><br>
> $ clang++ -fsanitize=float-cast-overflow test.cxx<br>
><br>
> runtime error: value 255.5 is outside the range of representable values of type 'unsigned char'<br>
><br>
> Now, I'm no language lawyer, but the standard seems to say "An rvalue of a floating point type can be converted to an rvalue of an integer type. The conversion truncates; that is, the fractional part is discarded. The behavior is undefined if the ***truncated*** value cannot be represented in the destination type." (emphasis mine)<br>
><br>
> So is clang wrong to complain here?<br>
<br>
</div>I tend to agree with you, +Richard Smith to make him aware of/get his opinion.<br>
</blockquote></div><br><div>Yes, I also agree. Please file a bug!</div>