spir: > But this does not explain why the compiler refuses: > // 1 > auto s = S(data); > return &s; > and accepts: > // 2 > return &(S(data)); > or does it?
Accepting the second is a bug in the escape analysis done by the front-end, I think. But see also what Walter has invented here: http://en.wikipedia.org/wiki/Return_value_optimization > What are the supposed differences in semantics or behaviour, if any? Regarding what the compiler actually does, take a look at the produced asm. > (This is just a synopsis). I need to write it that way, else it's refused. Don't return pointers to memory present in to-be-deleted stack frames. Bye, bearophile