Commit e67bf044 by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/69902 (Bogus -Wnonnull-compare for: dynamic_cast<T*>(&ref) == nullptr)

	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
parent f1a62b6f
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.
......
......@@ -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)
......
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.
......
// 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" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment