public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Manuel López-Ibáñez" <lopezibanez@gmail.com>
To: "Scott Lipcon" <slipcon@gmail.com>
Cc: "Ian Lance Taylor" <iant@google.com>, gcc-help@gcc.gnu.org
Subject: Re: floating point warnings, and gcc 4 warnings in general
Date: Mon, 31 Jul 2006 17:35:00 -0000	[thread overview]
Message-ID: <6c33472e0607311035j43cd9cc8i2de55358ae920c58@mail.gmail.com> (raw)
In-Reply-To: <m38xmy6iv8.fsf@localhost.localdomain>

Hi Scott, sorry for the late reply.

My current code gives the following warnings for your testcase (all of
them plus one bonus extra warning):

tryFloat.C:12: warning: coercion to 'float' from 'const double' may
alter its value
  int Test::getDI() const
tryFloat.C:15: warning: coercion to 'int' from 'const double' may
alter its value
  void Test::setI(const int&) int Test::getI() const short int
Test::getIS() const
tryFloat.C:19: warning: coercion to 'short int' from 'const int' may
alter its value
 int main(int, char**)
tryFloat.C:31: warning: coercion to 'float' from 'double' may alter its value

You can get the patches from http://gcc.gnu.org/wiki/Wcoercion#Download

It would be great if you can test the patches or provide more
testcases or add something to the documentation (
http://gcc.gnu.org/wiki/Wcoercion ). Any feedback is welcome.

Happy coding!

Manuel.


On 13 Jul 2006 00:53:31 -0700, Ian Lance Taylor <iant@google.com> wrote:
> "Scott Lipcon" <slipcon@gmail.com> writes:
>
> >  I'm trying to figure out how to get gcc to warn on a specific problem
> > that we found in our source code.   I've attached a simple test
> > program that has a few places where floating point precision can
> > potentially be lost or cause problems.   Specifically:
> >     1)   Line 12,  returns a double as a float without an explicit
> > cast - loss of precision.  Would like a warning here.
> >     2)  Line 19,  same problem, but with fixed point - returns an int
> > as a short, without a cast - loss of precision, would like a warning
> >     3)  Line 31,  subtracts a float from a double (the constant is
> > treated as a double, the variable is explicitly cast as a float.   In
> > this particular case, as can be seen in the printf on line 34,  pi/2 -
> > pi/2 does not equal zero.   This seems like it might be harder to
> > check for, but I'd love to see a warning here as well.
>
> Manuel López-Ibáñez is working on warnings along these lines as part
> of a Google Summer of Code project.  See
>     http://gcc.gnu.org/wiki/Wcoercion
>
> Ian
>

      reply	other threads:[~2006-07-31 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-12 14:45 Scott Lipcon
2006-07-13  7:53 ` Ian Lance Taylor
2006-07-31 17:35   ` Manuel López-Ibáñez [this message]

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=6c33472e0607311035j43cd9cc8i2de55358ae920c58@mail.gmail.com \
    --to=lopezibanez@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=iant@google.com \
    --cc=slipcon@gmail.com \
    /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).