diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2011-09-28 22:04:48 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2011-09-28 22:04:48 +0000 |
commit | 6f94398e396918f4d244cc60991b1fc8f28941fc (patch) | |
tree | 7288113c3410ad7be6e2e1844c8ca4e76f8cbb26 /gcc/cp | |
parent | 39f2bcb5e15aa41a156ac55a0466aa3bb82bc327 (diff) | |
download | gcc-6f94398e396918f4d244cc60991b1fc8f28941fc.zip gcc-6f94398e396918f4d244cc60991b1fc8f28941fc.tar.gz gcc-6f94398e396918f4d244cc60991b1fc8f28941fc.tar.bz2 |
re PR c++/45278 (-Wextra doesn't warn about (pointer < 0 ).)
/cp
2011-09-28 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/45278
* typeck.c (cp_build_binary_op): With -Wextra, warn for ordered
comparison of pointer with zero.
/testsuite
2011-09-28 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/45278
* g++.dg/warn/Wextra-3.C: New.
From-SVN: r179321
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 14 |
2 files changed, 18 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 596d4a9..68e702f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-09-28 Paolo Carlini <paolo.carlini@oracle.com> + + PR c++/45278 + * typeck.c (cp_build_binary_op): With -Wextra, warn for ordered + comparison of pointer with zero. + 2011-09-27 Paolo Carlini <paolo.carlini@oracle.com> PR c++/31489 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 10f17bf..d416b42 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4189,9 +4189,19 @@ cp_build_binary_op (location_t location, result_type = composite_pointer_type (type0, type1, op0, op1, CPO_COMPARISON, complain); else if (code0 == POINTER_TYPE && null_ptr_cst_p (op1)) - result_type = type0; + { + result_type = type0; + if (extra_warnings && (complain & tf_warning)) + warning (OPT_Wextra, + "ordered comparison of pointer with integer zero"); + } else if (code1 == POINTER_TYPE && null_ptr_cst_p (op0)) - result_type = type1; + { + result_type = type1; + if (extra_warnings && (complain & tf_warning)) + warning (OPT_Wextra, + "ordered comparison of pointer with integer zero"); + } else if (null_ptr_cst_p (op0) && null_ptr_cst_p (op1)) /* One of the operands must be of nullptr_t type. */ result_type = TREE_TYPE (nullptr_node); |