DMD Symbol Reference Analysis Pass

via Digitalmars-d digitalmars-d at puremagic.com
Tue May 26 07:59:36 PDT 2015


On Tuesday, 26 May 2015 at 10:19:52 UTC, Marc Schütz wrote:
> ... to be used in templates and for enforcing these rules:
> http://wiki.dlang.org/User:Schuetzm/scope3#.40safe-ty_violations_with_borrowing

There's at least a plan. Nice!

One thing, though. I'm lacking a section in the document linked 
above on how `foreach` could be `scope`-enhanced so that an 
element reference of an aggregate doesn't escape its foreach 
scope.

     char[] saved_line;
     string saved_str;
     foreach (scope line; File("foo.txt").byLine)
     {
         saved_line = line; // should give error
         saved_line = line.dup; // should be ok
         saved_str  = line.to!string; // should be ok
     }

provided that `byLine` returns a reference to a volatile internal 
buffer.


More information about the Digitalmars-d mailing list