https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |74762 --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- 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)