@@ -507,10 +507,12 @@ get_typeid (tree type, tsubst_flags_t co
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)),
+ tree cond = build2 (EQ_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,
cp_convert (TREE_TYPE (result), nullptr_node, complain),
result);
}
@@ -2101,6 +2101,11 @@ cp_fold (tree x)
else
x = fold (x);
+ if (COMPARISON_CLASS_P (TREE_OPERAND (org_x, 0))
+ && TREE_NO_WARNING (TREE_OPERAND (org_x, 0))
+ && TREE_CODE (x) == TREE_CODE (org_x)
+ && COMPARISON_CLASS_P (TREE_OPERAND (x, 0)))
+ TREE_NO_WARNING (TREE_OPERAND (x, 0)) = 1;
break;
case CALL_EXPR:
@@ -0,0 +1,14 @@
+// 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;
+}