The C++ standard states that returning reference to a local variable (on the stack) is undefined behaviour, so why do many (if not all) of the current compilers only
Because standard does not restrict us.
If you want to shoot to your own foot you can do it!
However lets see and example where it can be useful:
int &foo() { int y; } bool stack_grows_forward() { int &p=foo(); int my_p; return &my_p < &p; }