[cfe-dev] Warn on invalid fp-to-int conversions?

Hal Finkel via cfe-dev cfe-dev at lists.llvm.org
Fri Jan 20 08:52:07 PST 2017


On 01/20/2017 10:49 AM, Krzysztof Parzyszek via cfe-dev wrote:
> Hi,
> Consider this program:
>
> #include <math.h>
> int foo() {
>   int a = (int)INFINITY;
>   int b = (int)NAN;
>   return a+b;
> }
>
> It compiles without warnings (using -Wall), however neither of the 
> conversions will result in anything useful. Would it be reasonable to 
> have a warning about these kinds of conversions?

As I recall, these conversions, as well as any out-of-range conversions, 
are UB, and we should warn.

  -Hal

>
> -Krzysztof
>

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory




More information about the cfe-dev mailing list