+2016-02-19 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/69850
+ * rtti.c (ifnonnull): Set TREE_NO_WARNING on the condition, use
+ NE_EXPR instead of EQ_EXPR and swap last two arguments on COND_EXPR.
+
2016-02-19 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/68948
static tree
ifnonnull (tree test, tree result, tsubst_flags_t complain)
{
- return build3 (COND_EXPR, TREE_TYPE (result),
- build2 (EQ_EXPR, boolean_type_node, test,
- cp_convert (TREE_TYPE (test), nullptr_node,
- complain)),
- cp_convert (TREE_TYPE (result), nullptr_node, complain),
- result);
+ tree cond = build2 (NE_EXPR, boolean_type_node, test,
+ cp_convert (TREE_TYPE (test), nullptr_node, complain));
+ /* This is a compiler generated comparison, don't emit
+ e.g. -Wnonnull-compare warning for it. */
+ TREE_NO_WARNING (cond) = 1;
+ return build3 (COND_EXPR, TREE_TYPE (result), cond, result,
+ cp_convert (TREE_TYPE (result), nullptr_node, complain));
}
/* Execute a dynamic cast, as described in section 5.2.6 of the 9/93 working
--- /dev/null
+// PR c++/69850
+// { dg-do compile }
+// { dg-options "-Wnonnull-compare" }
+
+struct A { virtual ~A (); int foo (); };
+struct B { virtual ~B () { } };
+struct C : B, A { };
+
+int
+A::foo ()
+{
+ C *c = dynamic_cast<C *> (this); // { dg-bogus "nonnull argument" }
+ return !c;
+}