public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-99251-4-fzJLsLWFLk@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-99251-4@http.gcc.gnu.org/bugzilla/> 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)
next prev parent reply other threads:[~2021-02-24 18:14 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-24 16:21 [Bug c++/99251] New: Strange " sirl at gcc dot gnu.org 2021-02-24 17:12 ` [Bug c++/99251] [11 Regression] inconsistent " msebor at gcc dot gnu.org 2021-02-24 17:13 ` msebor at gcc dot gnu.org 2021-02-24 18:14 ` msebor at gcc dot gnu.org [this message] 2021-02-24 22:29 ` msebor at gcc dot gnu.org 2021-02-25 7:59 ` rguenth at gcc dot gnu.org 2021-03-02 18:17 ` cvs-commit at gcc dot gnu.org 2021-03-02 18:18 ` msebor at gcc dot gnu.org 2021-06-28 20:13 ` msebor at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99251-4-fzJLsLWFLk@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).