Tested with dmd 2.63.2. Trying to return a ref int to a local int errors correctly as does a `scope A a = new A()`. --- import std.typecons, std.stdio; class A { } // Using auto ref because I don't know how to get the type of scoped // (I guess I should file this behavior as a bug too) auto ref fun() { auto a = scoped!A(); writefln("%x", &a); return a; // Compiler should output: // Error: escaping reference to scope local a } void main() { auto a = fun(); writefln("%x", &a); } ---
scope documentation says: > This facility is unsafe; > it is the responsibility of the user to not escape a reference to the > object outside the scope. so it's invalid to the extent that it's specified.