Commit ae311566 by Ralf Wildenhues Committed by Ralf Wildenhues

re PR c/19999 (-Wfloat-equal does not warn for complex numbers)

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

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

gcc/testsuite/:
* gcc.dg/Wfloat-equal-1.c: New.
* g++.dg/warn/Wfloat-equal-1.C: New.

From-SVN: r132540
parent 24219f12
2008-02-22 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.
2008-02-21 Janis Johnson <janis187@us.ibm.com> 2008-02-21 Janis Johnson <janis187@us.ibm.com>
PR target/34526 PR target/34526
......
...@@ -8138,7 +8138,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -8138,7 +8138,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
case EQ_EXPR: case EQ_EXPR:
case NE_EXPR: case NE_EXPR:
if (code0 == REAL_TYPE || code1 == REAL_TYPE) if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
warning (OPT_Wfloat_equal, warning (OPT_Wfloat_equal,
"comparing floating point with == or != is unsafe"); "comparing floating point with == or != is unsafe");
/* Result of comparison is always int, /* Result of comparison is always int,
......
2008-02-22 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
PR c/19999
* typeck.c (build_binary_op): Warn about floating point
comparisons if FLOAT_TYPE_P, not only for REAL_TYPE.
2008-02-19 Jason Merrill <jason@redhat.com> 2008-02-19 Jason Merrill <jason@redhat.com>
PR c++/34950 PR c++/34950
......
...@@ -3359,7 +3359,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -3359,7 +3359,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
case EQ_EXPR: case EQ_EXPR:
case NE_EXPR: case NE_EXPR:
if (code0 == REAL_TYPE || code1 == REAL_TYPE) if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
warning (OPT_Wfloat_equal, warning (OPT_Wfloat_equal,
"comparing floating point with == or != is unsafe"); "comparing floating point with == or != is unsafe");
if ((TREE_CODE (orig_op0) == STRING_CST && !integer_zerop (op1)) if ((TREE_CODE (orig_op0) == STRING_CST && !integer_zerop (op1))
......
2008-02-22 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
PR c/19999
* gcc.dg/Wfloat-equal-1.c: New.
* g++.dg/warn/Wfloat-equal-1.C: New.
2008-02-21 Michael Matz <matz@suse.de> 2008-02-21 Michael Matz <matz@suse.de>
PR target/35264 PR target/35264
/* 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" } */
/* 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" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment