https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86176
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2018-06-18 Ever confirmed|0 |1 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- The warning depends on inlining which makes it require -O2 in your case and with the cout line uncommented the inlining doesn't take place because of cost reasons. Making f static shows > g++-7 t.C -O2 -Wnull-dereference t.C: In function ‘int main()’: t.C:6:11: warning: null pointer dereference [-Wnull-dereference] printf("%d\n", *i); ~~~~~~^~~~~~~~~~~~ t.C:7:19: warning: null pointer dereference [-Wnull-dereference] std::cout << *i; ^ so confirmed but the issues are by design. GCC isn't a static analyzer.