Re: Warn about conversion from floating point to integers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

On Sat, Aug 20, 2022 at 11:21:50AM +0200, Andrea Bocci wrote:
> is there a way to ask GCC to produce a warning when there is a conversion
> from a floating point type (float or double) to an integer type (char,
> short, int, long, etc.), but not when there is a conversion from double to
> float ?
> 
> The reason is that we often do computations in double precision and store
> the result in single precision, so I'd rather not warn about that.
> 
> -Wconversion warns about both kinds and more.
> -Wfloat-conversion warns about both kinds.

There is no separate option.  But, you can just grep the error messages?

fc.c: In function 'f':
fc.c:1:28: warning: conversion from 'double' to 'float' may change value [-Wfloat-conversion]
    1 | float f(double x) { return x; }
      |                            ^
fc.c: In function 'g':
fc.c:2:26: warning: conversion from 'double' to 'int' may change value [-Wfloat-conversion]
    2 | int g(double x) { return x; }
      |                          ^

Not ideal of course, but this should be workable?  (You may want to set
LANG=C to get parsable warning messages).

If you want a separate -W option for this, please file a PR?
See <https://gcc.gnu.org/bugs.html>.  Thanks!


Segher



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux