https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82520
Bug ID: 82520 Summary: Missing warning when stack addresses escape the current scope Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ajax at redhat dot com Target Milestone: --- Testcase: ----- #include <malloc.h> struct foo { void *v; }; struct foo *bar(void) { int a[10]; struct foo *ret = malloc(sizeof(struct foo)); ret->v = &a; return ret; } ----- The address of 'a' is just somewhere on the stack. There might be rare cases where you'd want to do this, but usually this would be a bug. Bug 63181 is perhaps a C++ variation of the same kind of problem, but clang doesn't warn for this one.