[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-06-28 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251
Bug 99251 depends on bug 74762, which changed state.

Bug 74762 Summary: [9/10/11 Regression] missing uninitialized warning (C++, 
parenthesized expr, TREE_NO_WARNING)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=74762

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-03-02 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

Martin Sebor  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #5 from Martin Sebor  ---
Fixed in r11-7458.

[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-03-02 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Martin Sebor :

https://gcc.gnu.org/g:66ecb059c9d77cfcfb06cbdc3cac6a63b9e67f3d

commit r11-7458-g66ecb059c9d77cfcfb06cbdc3cac6a63b9e67f3d
Author: Martin Sebor 
Date:   Tue Mar 2 11:12:50 2021 -0700

PR c++/99251 - inconsistent -Wnonnull warning behaviour with dynamic_cast

gcc/cp/ChangeLog:

PR c++/99251
* class.c (build_base_path): Call build_if_nonnull.
* cp-tree.h (build_if_nonnull): Declare.
* rtti.c (ifnonnull): Rename...
(build_if_nonnull): ...to this.  Set no-warning bit on COND_EXPR.
(build_dynamic_cast_1): Adjust to name change.

gcc/testsuite/ChangeLog:

PR c++/99251
* g++.dg/warn/Wnonnull9.C: Expect no warnings.
* g++.dg/warn/Wnonnull12.C: New test.

[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-02-24 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |11.0

[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-02-24 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #3 from Martin Sebor  ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565824.html

[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-02-24 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

Martin Sebor  changed:

   What|Removed |Added

 Depends on||74762

--- Comment #2 from Martin Sebor  ---
The reason why there's no warning for cl3::g() is because the result of the
cast is not dereferenced in the same expression (the -Wnonnull warning is
issued for the call, and the call is in the next statement).

The reason why there's no warning for the parenthesized cast in cl3::h() is due
to pr74762: the C++ front end sets the no-warning bit on the parenthesized
expression.  The warning sees this IL:

  cl2::h (((struct cl3 *) this)->p != 0B ? (struct cl2 *) __dynamic_cast
(this->p, &_ZTI3cl1, &_ZTI3cl2, 0) : 0B)

where both the COND_EXPR (?:) and the NE_EXPR (!=) have the no-warning bit set
and the warning code uses the first bit to suppress it.

The reason why there is a warning for cl3::i() is because the no-warning bit is
set only on the NE_EXPR and not on the COND_EXPR as above, and the warning code
only tests the latter.

Finally, the reason why the warning is not issued for a similar static_cast
(where the argument has to be checked for equality to null in order for the
result to stay null) is because of the fix for pr96003 that set the no-warning
bit even on the COND_EXPR but didn't make the corresponding change in
ifnonnull() in cp/rtti.c.  What a mess.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=74762
[Bug 74762] [8/9/10/11 Regression] missing uninitialized warning (C++,
parenthesized expr, TREE_NO_WARNING)

[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-02-24 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

Martin Sebor  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |msebor at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

[Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast

2021-02-24 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

Martin Sebor  changed:

   What|Removed |Added

 Blocks||95507
   Last reconfirmed||2021-02-24
   Keywords||diagnostic
Summary|Strange -Wnonnull warning   |[11 Regression]
   |behaviour with dynamic_cast |inconsistent -Wnonnull
   ||warning behaviour with
   ||dynamic_cast
 Ever confirmed|0   |1
 CC||msebor at gcc dot gnu.org
 Status|UNCONFIRMED |NEW

--- Comment #1 from Martin Sebor  ---
We discussed this instance of the warning in pr98646 and decided that even
though issuing it for an access to the result of dynamic_cast was strictly a
false positive when the operand was guaranteed to be nonnull by a prior test,
the workaround to cast to a reference rather than a pointer was simple enough
and made the intent clearer:

  return dynamic_cast(*p).i();

But the inconsistency exhibited in this test case is not a good thing
(enclosing the cast in parentheses certainly shouldn't make a difference) and
suggests the decision should be revisited.  The warning for the dynamic_cast
should either be issued consistently or not at all.  Let me look into it.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95507
[Bug 95507] [meta-bug] bogus/missing -Wnonnull