[PATCH] PR c/19999

Ralf Wildenhues Ralf.Wildenhues@gmx.de
Thu Feb 21 06:58:00 GMT 2008


OK for trunk?  Bootstrapped, regtested on i686-pc-linux-gnu.

This is my first commit to GCC code proper (as opposed to docs, build
machinery, or trivial patches), so please be gentle and scrupulous.

Thanks,
Ralf

gcc/ChangeLog:
2008-02-21  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>

	PR c/19999
	* c-typeck.c (build_binary_op): Warn about floating point
	comparisons if FLOAT_TYPE_P, not only for REAL_TYPE.

gcc/testsuite/ChangeLog:
2008-02-21  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>

	PR c/19999
	* gcc.dg/Wfloat-equal-1.c: New.

diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 60b0b02..55b4b23 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -8138,7 +8138,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
 
     case EQ_EXPR:
     case NE_EXPR:
-      if (code0 == REAL_TYPE || code1 == REAL_TYPE)
+      if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
 	warning (OPT_Wfloat_equal,
 		 "comparing floating point with == or != is unsafe");
       /* Result of comparison is always int,
diff --git a/gcc/testsuite/gcc.dg/Wfloat-equal-1.c b/gcc/testsuite/gcc.dg/Wfloat-equal-1.c
new file mode 100644
index 0000000..36b3fa5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wfloat-equal-1.c
@@ -0,0 +1,10 @@
+/* PR c/19999 */
+/* { dg-do compile } */
+/* { dg-options "-Wfloat-equal" } */
+
+double a, b;
+_Complex double c, d;
+int f(void) { return a == b; } /* { dg-warning "comparing floating point" } */
+int g(void) { return c == d; } /* { dg-warning "comparing floating point" } */
+int h(void) { return a != b; } /* { dg-warning "comparing floating point" } */
+int i(void) { return c != d; } /* { dg-warning "comparing floating point" } */



More information about the Gcc-patches mailing list