diff options
author | Dirk Zoller <duz@rtsffm.com> | 1999-09-30 06:15:53 +0000 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 1999-09-30 00:15:53 -0600 |
commit | 1bdba2c09c51979c2ec3387637e87648b0ac1db6 (patch) | |
tree | bf9873a84808d407222be4f9b9123c3fe39dbee6 /gcc/cp | |
parent | 061f7e47214c16895074ea9ffcd1ceeb4aa67829 (diff) | |
download | gcc-1bdba2c09c51979c2ec3387637e87648b0ac1db6.zip gcc-1bdba2c09c51979c2ec3387637e87648b0ac1db6.tar.gz gcc-1bdba2c09c51979c2ec3387637e87648b0ac1db6.tar.bz2 |
cp-tree.h (warn_float_equal): Declare.
* cp-tree.h (warn_float_equal): Declare.
* decl2.c (warn_float_equal): Define.
(lang_decode_option): Recognize -W[no-]float-equal.
* typeck.c (build_binary_op_nodefault): Conditionally warn
about equality tests of floating point types.
From-SVN: r29721
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 4 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 6 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 3 |
4 files changed, 21 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 43ebd72..356e7c6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +Thu Sep 30 00:13:27 1999 Dirk Zoller <duz@rtsffm.com> + + * cp-tree.h (warn_float_equal): Declare. + * decl2.c (warn_float_equal): Define. + (lang_decode_option): Recognize -W[no-]float-equal. + * typeck.c (build_binary_op_nodefault): Conditionally warn + about equality tests of floating point types. + 1999-09-29 Jason Merrill <jason@yorick.cygnus.com> Support normal type_info-based EH mechanisms with -fno-rtti. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index cd3a2dd..a3146dd 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -893,6 +893,10 @@ extern int warn_missing_braces; extern int warn_sign_compare; +/* Warn about testing equality of floating point numbers. */ + +extern int warn_float_equal; + /* Warn about a subscript that has type char. */ extern int warn_char_subscripts; diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 6fb90fe..22e03f3 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -277,6 +277,10 @@ int warn_missing_braces; int warn_sign_compare; +/* Warn about testing equality of floating point numbers. */ + +int warn_float_equal = 0; + /* Warn about *printf or *scanf format/argument anomalies. */ int warn_format; @@ -689,6 +693,8 @@ lang_decode_option (argc, argv) warn_missing_braces = setting; else if (!strcmp (p, "sign-compare")) warn_sign_compare = setting; + else if (!strcmp (p, "float-equal")) + warn_float_equal = setting; else if (!strcmp (p, "format")) warn_format = setting; else if (!strcmp (p, "conversion")) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 6a18b11..4a28de2 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3574,6 +3574,9 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) case EQ_EXPR: case NE_EXPR: + if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE)) + warning ("comparing floating point with == or != is unsafe"); + build_type = boolean_type_node; if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE) |