public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Andrea Bocci <andrea.bocci@cern.ch>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Warn about conversion from floating point to integers
Date: Mon, 22 Aug 2022 12:32:03 -0500	[thread overview]
Message-ID: <20220822173203.GP25951@gate.crashing.org> (raw)
In-Reply-To: <CAAK6D=7L4J3o6_WutEKvTt2WhJNXCfywz-1_0mErboywbRp2Hw@mail.gmail.com>

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

  reply	other threads:[~2022-08-22 17:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-20  9:21 Andrea Bocci
2022-08-22 17:32 ` Segher Boessenkool [this message]
2022-08-22 19:27   ` Andrea Bocci
2022-08-22 19:43     ` Jonathan Wakely
2022-08-22 19:48       ` Andrea Bocci
2022-08-22 23:01         ` Segher Boessenkool
2022-08-22 23:39           ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220822173203.GP25951@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=andrea.bocci@cern.ch \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).