Commit 7a965d51 by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/69850 (unnecessary -Wnonnull-compare warning)

	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.

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

From-SVN: r233568
parent c464c0db
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> 2016-02-19 Patrick Palka <ppalka@gcc.gnu.org>
PR c++/68948 PR c++/68948
......
...@@ -507,12 +507,13 @@ get_typeid (tree type, tsubst_flags_t complain) ...@@ -507,12 +507,13 @@ get_typeid (tree type, tsubst_flags_t complain)
static tree static tree
ifnonnull (tree test, tree result, tsubst_flags_t complain) ifnonnull (tree test, tree result, tsubst_flags_t complain)
{ {
return build3 (COND_EXPR, TREE_TYPE (result), tree cond = build2 (NE_EXPR, boolean_type_node, test,
build2 (EQ_EXPR, boolean_type_node, test, cp_convert (TREE_TYPE (test), nullptr_node, complain));
cp_convert (TREE_TYPE (test), nullptr_node, /* This is a compiler generated comparison, don't emit
complain)), e.g. -Wnonnull-compare warning for it. */
cp_convert (TREE_TYPE (result), nullptr_node, complain), TREE_NO_WARNING (cond) = 1;
result); 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 /* Execute a dynamic cast, as described in section 5.2.6 of the 9/93 working
......
2016-02-19 Jakub Jelinek <jakub@redhat.com> 2016-02-19 Jakub Jelinek <jakub@redhat.com>
PR c++/69850
* g++.dg/warn/Wnonnull-compare-4.C: New test.
PR c++/69851 PR c++/69851
* g++.dg/torture/pr69851.C: New test. * g++.dg/torture/pr69851.C: New test.
......
// 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;
}
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