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

            Bug ID: 127090
           Summary: -Wuse-after-free does not warn on trivial example
                    anymore
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico at kircheis dot it
  Target Milestone: ---

Consider following snippet

----
void foo(int);

int main() {
   int* ptr = new int(42);
   delete ptr;                    

   int value = *ptr;              
   foo(value);
}
----

with gcc 15.1 -Wuse-after-free -O2:

----
<source>: In function 'int main()':
<source>:7:8: warning: pointer used after 'void operator delete(void*, long
unsigned int)' [-Wuse-after-free]
    7 |    int value = *ptr;
      |        ^~~~~
<source>:5:11: note: call to 'void operator delete(void*, long unsigned int)'
here
    5 |    delete ptr;
      |           ^~~
Compiler returned: 0
----


with gcc 16 / trunk, there is no diagnostic

Example on godbolt: https://godbolt.org/z/vqKb7aof1

Reply via email to