https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94355
--- Comment #4 from David Malcolm <dmalcolm at gcc dot gnu.org> --- (In reply to Ivan Sorokin from comment #0) > At the moment static analyzer warns about leaked malloc. It would be great > if C++ new expression were also supported. > > Example: > > void f() > { > char* p = new char; > } > > Expected diagnostic: > > warning: leak of 'p' [CWE-401] [-Wanalyzer-malloc-leak] > > 3 | char* p = new char; Actual diagnostic with commit r11-3090-g1690a839cff2e0276017a013419d81d675bbf69d: demo.cc: In function ‘void f()’: demo.cc:4:1: warning: leak of ‘p’ [CWE-401] [-Wanalyzer-malloc-leak] 4 | } | ^ ‘void f()’: events 1-2 | | 3 | char* p = new char; | | ^~~~ | | | | | (1) allocated here | 4 | } | | ~ | | | | | (2) ‘p’ leaks here; was allocated at (1) | where the diagnostic's location is at the point where "p" goes out of scope. There's an argument that it would be better emitting it at the "new".