http://d.puremagic.com/issues/show_bug.cgi?id=2509
2kor...@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |2kor...@gmail.com Summary|ref return doesn't work for |Compiler rejects inner |inner function (found 'ref' |function that return |instead of statement ) |references ------- Comment #1 from 2kor...@gmail.com 2008-12-12 18:11 ------- The following code doesn't work either: void main() { int i; int* func() { return &i; // Error: escaping reference to local variable i } } Replace a pointer with a reference and you get the same semantics and thus your code wont work, too. An errot message reminds me about escape analysis discussion past month and I think that this behaviour needs some additional elaboration from Walter because it never was announces nor documented. The analysis implemente, however, is not too smart as there are ways to trick it: void main() { int i; void func(ref int* p) { p = &i; // Okay, no complains here } } Other than this, looks like compiler isn't yet aware of inner functions that return references (it doesn't expect to find a 'ref' keyword at a function level). It makes the following valid code fail to compile: void main() { ref int func() { static int foo; return foo; } func = 4; } --