]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/69902 (Bogus -Wnonnull-compare for: dynamic_cast<T*>(&ref) == nullptr)
authorJakub Jelinek <jakub@redhat.com>
Tue, 23 Feb 2016 12:58:53 +0000 (13:58 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 23 Feb 2016 12:58:53 +0000 (13:58 +0100)
PR c++/69902
* fold-const.c (fold_truth_not_expr): Propagate TREE_NO_WARNING
when inverting comparison.

* g++.dg/warn/Wnonnull-compare-5.C: New test.

From-SVN: r233631

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wnonnull-compare-5.C [new file with mode: 0644]

index 020a1b3485ae3f96290711d9602411486faa900a..951f2084cef640d64f373574175742ccf17da1a0 100644 (file)
@@ -1,5 +1,9 @@
 2016-02-23  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/69902
+       * fold-const.c (fold_truth_not_expr): Propagate TREE_NO_WARNING
+       when inverting comparison.
+
        PR c/69900
        * common.opt (Wunreachable-code): Add Warning flag.
 
index 41c652e43ee5ed828c603598c0e21c97415cafe7..5376d4d499c06985ad8b7c87e8df9f2316fa836a 100644 (file)
@@ -3589,8 +3589,11 @@ fold_truth_not_expr (location_t loc, tree arg)
       if (code == ERROR_MARK)
        return NULL_TREE;
 
-      return build2_loc (loc, code, type, TREE_OPERAND (arg, 0),
-                        TREE_OPERAND (arg, 1));
+      tree ret = build2_loc (loc, code, type, TREE_OPERAND (arg, 0),
+                            TREE_OPERAND (arg, 1));
+      if (TREE_NO_WARNING (arg))
+       TREE_NO_WARNING (ret) = 1;
+      return ret;
     }
 
   switch (code)
index f83aa50ff2e166f8059ca26d00a47429f6add956..2b7fe37821d29b3ea21db0c94509d101985fbeff 100644 (file)
@@ -1,5 +1,8 @@
 2016-02-23  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/69902
+       * g++.dg/warn/Wnonnull-compare-5.C: New test.
+
        PR c/69900
        * gcc.dg/pr69900.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull-compare-5.C b/gcc/testsuite/g++.dg/warn/Wnonnull-compare-5.C
new file mode 100644 (file)
index 0000000..8b31e6c
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/69902
+// { dg-do compile }
+// { dg-options "-Wall" }
+
+struct A { virtual ~A (); };
+struct B : A {};
+
+bool
+foo (A &a)
+{
+  return dynamic_cast<B *>(&a) == (B *) 0;     // { dg-bogus "nonnull argument" }
+}
+
+bool
+bar (A &a)
+{
+  return dynamic_cast<B *>(&a) != (B *) 0;     // { dg-bogus "nonnull argument" }
+}