int* f() {
int a = 2; // <<---
return &a; // uses escape analysis to determine that a must be an object in a garbage collected heap, or a reference counted object on the heap, since ints can't reference other stuff to make cycles.
}
int* f() {
stack int a = 2;
return &a; // uses escape analysis to determine that this will lead to memory errors, and wont compile.
}
I think this would make more sense in a gc is normal language, like java or some of the functional garbage collected languages where pass by reference is the only paassing.