https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251
Martin Sebor <msebor at gcc dot gnu.org> 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 <msebor at gcc dot gnu.org> --- 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<cl2 &>(*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