From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 12B6B38708EC; Wed, 24 Feb 2021 18:14:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12B6B38708EC From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99251] [11 Regression] inconsistent -Wnonnull warning behaviour with dynamic_cast Date: Wed, 24 Feb 2021 18:14:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: msebor at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: dependson Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Feb 2021 18:14:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99251 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 !=3D 0B ? (struct cl2 *) __dynamic_cast (this->p, &_ZTI3cl1, &_ZTI3cl2, 0) : 0B) where both the COND_EXPR (?:) and the NE_EXPR (!=3D) have the no-warning bi= t 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 bi= t 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-warn= ing 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=3D74762 [Bug 74762] [8/9/10/11 Regression] missing uninitialized warning (C++, parenthesized expr, TREE_NO_WARNING)=