This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
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
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.
"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
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |