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

            Bug ID: 117329
           Summary: -Wnull-dereference error indicator in the wrong place
                    when inlining methods.
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: o.putaans at gmail dot com
  Target Milestone: ---

Created attachment 59471
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59471&action=edit
Preprocessed source file.

gcc version 14.2.0 (Ubuntu 14.2.0-4ubuntu2~24.04) 
Target: x86_64-linux-gnu

When compiling the code with `g++-14 -O1 -Wnull-dereference main.cpp`
The compiler returns a warning
```
In member function ‘void T2::setVar(int)’,
    inlined from ‘int main()’ at main.cpp:22:22:
main.cpp:6:13: warning: null pointer dereference [-Wnull-dereference]
    6 |         var = a;
      |         ~~~~^~~
```
The same warning was found for other -OX where X > 1. -O0 did not report this
warning at all.

That reported warning is in the wrong place. It seems to report the hidden
`this` variable in that line as being null, but it should have been reported
far earlier - the 3rd to last line `t->getA()->setVar(5);` as t is the variable
that is being null dereferenced. I'd expect that line to be reported 

This is a simplified version of what I encountered in the wild and that code
had a potential null pointer dereference, but this is close enough to what I
could isolate.

Reply via email to