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
You could also return a reference to a static variable, which would be valid code so the code must be able to compile.