* c-tree.h (warn_float_equal): Declare.
* c-decl.c (warn_float_equal): Define.
(c_decode_option): Recognize -W[no-]float-equal.
* c-typeck.c (build_binary_op): Conditionally warn
about equality tests of floating point types.
* toplev.c (documented_lan_options): Add -W[no-]float-equal.
From-SVN: r29722
+Thu Sep 30 00:13:27 1999 Dirk Zoller <duz@rtsffm.com>
+
+ * c-tree.h (warn_float_equal): Declare.
+ * c-decl.c (warn_float_equal): Define.
+ (c_decode_option): Recognize -W[no-]float-equal.
+ * c-typeck.c (build_binary_op): Conditionally warn
+ about equality tests of floating point types.
+ * toplev.c (documented_lan_options): Add -W[no-]float-equal.
+
Wed Sep 29 23:43:39 1999 Jeffrey A Law (law@cygnus.com)
* cse.c (struct set): Delete inner_dest_loc field.
int warn_sign_compare = -1;
+/* Warn about testing equality of floating point numbers. */
+
+int warn_float_equal = 0;
+
/* Nonzero means warn about use of multicharacter literals. */
int warn_multichar = 1;
warn_sign_compare = 1;
else if (!strcmp (p, "-Wno-sign-compare"))
warn_sign_compare = 0;
+ else if (!strcmp (p, "-Wfloat-equal"))
+ warn_float_equal = 1;
+ else if (!strcmp (p, "-Wno-float-equal"))
+ warn_float_equal = 0;
else if (!strcmp (p, "-Wmultichar"))
warn_multichar = 1;
else if (!strcmp (p, "-Wno-multichar"))
extern int warn_sign_compare;
+/* Warn about testing equality of floating point numbers. */
+
+extern int warn_float_equal;
+
/* Warn about multicharacter constants. */
extern int warn_multichar;
case EQ_EXPR:
case NE_EXPR:
+ if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE))
+ warning ("comparing floating point with == or != is unsafe");
/* Result of comparison is always int,
but don't convert the args to int! */
build_type = integer_type_node;
{ "-Wno-redundant-decls", "" },
{ "-Wsign-compare", "Warn about signed/unsigned comparisons" },
{ "-Wno-sign-compare", "" },
+ { "-Wfloat-equal", "Warn about testing equality of floating point numbers" },
+ { "-Wno-float-equal", "" },
{ "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
{ "-Wno-unknown-pragmas", "" },
{ "-Wstrict-prototypes", "Warn about non-prototyped function decls" },