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

--- Comment #8 from Sergei Trofimovich <slyfox at inbox dot ru> ---
(In reply to Sergei Trofimovich from comment #6)
> (In reply to Martin Sebor from comment #4)
> > The warning in the test case in comment #3 looks correct to me.
> 
> Thank you! I'll try to re-reduce and not introduce new NULLs.

Here is the second attempt at reducing firefox case, also related to
static_cast<>:

    struct D;
    struct B {
      B* next;
      D* Next();
    };

    struct D : public B {
      virtual ~D();
    };

    struct Iterator {
      D* current;
      void advance() {
        current = static_cast<B*>(current)->Next();
      }
    };

$ x86_64-pc-linux-gnu-g++ -o bug.o -c bug.cpp -Werror=nonnull
-fno-strict-aliasing
bug.cpp: In member function 'void Iterator::advance()':
bug.cpp:14:46: error: 'this' pointer null [-Werror=nonnull]
   14 |     current = static_cast<B*>(current)->Next();
      |                                              ^
bug.cpp:4:6: note: in a call to non-static member function 'D* B::Next()'
    4 |   D* Next();
      |      ^~~~
cc1plus: some warnings being treated as errors

Also, the "'this' pointer null" error wording is not very clear. Should it be
"'this' pointer is null"? Or "'this' pointer may be null"?

Reply via email to