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++/96003] [11 Regression] spurious -Wnonnull calling a member on the result of static_cast Date: Tue, 16 Feb 2021 20:14:24 +0000 [thread overview] Message-ID: <bug-96003-4-BIdNOQ7kiQ@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96003-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96003 --- Comment #24 from Martin Sebor <msebor at gcc dot gnu.org> --- I see. Yes, if the types are unrelated, that would be a likely bug. I think could and should be diagnosed by the C++ front end, by some more targeted warning than -Wnonnull (as requested in pr38557). But I didn't actually mean to write that test case in comment #20 (I forgot to derive one class from the other). The following is what I meant where the -Wnonnull is strictly a false positive because of the test. It can be avoided by casting *p to C& which might be argued (as I do in comment #17) makes the code clearer, but if this is a common idiom we could try to suppress the warning in these cases as well. Do you see this pattern a lot? struct A { virtual ~A (); }; struct C: A { virtual ~C (); void f (); }; void g (A *p) { if (dynamic_cast<C*>(p)) dynamic_cast<C*>(p)->f (); // -Wnonnull /* Avoid like so: if (dynamic_cast<C*>(p)) dynamic_cast<C&>(*p)->f (); */ }
next prev parent reply other threads:[~2021-02-16 20:14 UTC|newest] Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-30 11:38 [Bug tree-optimization/96003] New: Maybe a false positive for -Werror=nonnull marxin at gcc dot gnu.org 2020-06-30 11:45 ` [Bug tree-optimization/96003] " jakub at gcc dot gnu.org 2020-06-30 11:54 ` marxin at gcc dot gnu.org 2020-07-09 7:04 ` slyfox at inbox dot ru 2020-07-09 15:22 ` [Bug tree-optimization/96003] [11 Regression] " msebor at gcc dot gnu.org 2020-07-09 15:28 ` [Bug c++/96003] " msebor at gcc dot gnu.org 2020-07-09 17:40 ` slyfox at inbox dot ru 2020-07-15 6:59 ` rguenth at gcc dot gnu.org 2020-07-16 7:37 ` slyfox at inbox dot ru 2020-07-17 6:48 ` slyfox at inbox dot ru 2020-07-17 11:20 ` romain.geissler at amadeus dot com 2020-07-17 15:13 ` msebor at gcc dot gnu.org 2020-07-17 19:01 ` [Bug c++/96003] [11 Regression] spurious -Wnonnull calling a member on the result of static_cast msebor at gcc dot gnu.org 2020-07-21 19:27 ` sbergman at redhat dot com 2020-07-21 20:39 ` msebor at gcc dot gnu.org 2020-07-22 11:35 ` sbergman at redhat dot com 2020-07-30 7:36 ` marxin at gcc dot gnu.org 2020-07-30 14:30 ` msebor at gcc dot gnu.org 2020-07-31 16:29 ` cvs-commit at gcc dot gnu.org 2020-07-31 16:36 ` msebor at gcc dot gnu.org 2020-07-31 16:39 ` msebor at gcc dot gnu.org 2021-02-08 9:40 ` marxin at gcc dot gnu.org 2021-02-16 17:39 ` msebor at gcc dot gnu.org 2021-02-16 17:44 ` msebor at gcc dot gnu.org 2021-02-16 18:47 ` marxin at gcc dot gnu.org 2021-02-16 18:52 ` marxin at gcc dot gnu.org 2021-02-16 20:14 ` msebor at gcc dot gnu.org [this message] 2021-02-18 9:08 ` marxin at gcc dot gnu.org 2021-02-18 9:15 ` marxin at gcc dot gnu.org 2021-06-15 21:26 ` nyh at math dot technion.ac.il
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-96003-4-BIdNOQ7kiQ@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).