Hi Scott, sorry for the late reply. My current code gives the following warnings for your testcase (all ofthem plus one bonus extra warning): tryFloat.C:12: warning: coercion to 'float' from 'const double' mayalter its value int Test::getDI() consttryFloat.C:15: warning: coercion to 'int' from 'const double' mayalter its value void Test::setI(const int&) int Test::getI() const short intTest::getIS() consttryFloat.C:19: warning: coercion to 'short int' from 'const int' mayalter 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 moretestcases 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@xxxxxxxxxx> wrote:> "Scott Lipcon" <slipcon@xxxxxxxxx> 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>