]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/45278 (-Wextra doesn't warn about (pointer < 0 ).)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 28 Sep 2011 22:04:48 +0000 (22:04 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 28 Sep 2011 22:04:48 +0000 (22:04 +0000)
/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

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wextra-3.C [new file with mode: 0644]

index 596d4a97f7070544a55d7ffd90e7d8c84470491f..68e702fe8cf1dc3b9b7d20fd3c467f01cf16f0b9 100644 (file)
@@ -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
index 10f17bf0494a900d47328a39afd89bc75693d847..d416b42db3b0a9f4698705b11220937934bc62ca 100644 (file)
@@ -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);
index d19933a874697fdc6ca7824079bde128b764e165..ea1cad512019ee906870a0a060448f9900613549 100644 (file)
@@ -1,3 +1,8 @@
+2011-09-28  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/45278
+       * g++.dg/warn/Wextra-3.C: New.
+
 2011-09-28  Oleg Endo  <oleg.endo@t-online.de>
 
        PR target/49486
diff --git a/gcc/testsuite/g++.dg/warn/Wextra-3.C b/gcc/testsuite/g++.dg/warn/Wextra-3.C
new file mode 100644 (file)
index 0000000..04fdbba
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/45278
+// { dg-options "-Wextra" } 
+
+extern void* p;
+
+int f1() { return ( p <  0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }
+int f2() { return ( p <= 0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }
+int f3() { return ( p >  0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }
+int f4() { return ( p >= 0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }