public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99251] New: Strange -Wnonnull warning behaviour with dynamic_cast
@ 2021-02-24 16:21 sirl at gcc dot gnu.org
  2021-02-24 17:12 ` [Bug c++/99251] [11 Regression] inconsistent " msebor at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: sirl at gcc dot gnu.org @ 2021-02-24 16:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99251

            Bug ID: 99251
           Summary: Strange -Wnonnull warning behaviour with dynamic_cast
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sirl at gcc dot gnu.org
  Target Milestone: ---

With this testcase:

class cl1 {
  virtual void m();
};
class cl2 : public cl1 {
public:
  int g();
  int h();
  int i();
};
class cl3 {
  cl1 *p;
  int g();
  int h();
  int i();
};
int cl3::g() {
  if (!p)
    return 0;
  cl2 *x = dynamic_cast<cl2 *>(p);
  return x->g();
}
int cl3::h() {
  if (!p)
    return 0;
  return (dynamic_cast<cl2 *>(p))->h();
}
int cl3::i() {
  if (!p)
    return 0;
  return dynamic_cast<cl2 *>(p)->i();
}

compiled with g++-trunk@r11-7356 -Wnonnull this warning is issued:

testcase.cpp: In member function 'int cl3::i()':
testcase.cpp:30:36: warning: 'this' pointer is null [-Wnonnull]
   30 |   return dynamic_cast<cl2 *>(p)->i();
      |                                    ^
testcase.cpp:8:7: note: in a call to non-static member function 'int cl2::i()'
    8 |   int i();
      |       ^

I believe there should be no warning for cl3::i() like with g++-10.2.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-06-28 20:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 16:21 [Bug c++/99251] New: Strange -Wnonnull warning behaviour with dynamic_cast 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
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

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).