tupleof vs @safe

ag0aep6g anonymous at example.com
Fri Mar 2 23:52:02 UTC 2018


On 03/03/2018 12:22 AM, ag0aep6g wrote:
> But what about `tupleof`? It ignores `private` and it's allowed in 
> `@safe` code:
> 
> ----
[...]
> ----

Now that I've sent this, I find the affected Phobos type I couldn't 
pinpoint. It's `File`:

----
void main() @safe
{
     import std.stdio: File, writeln;
     auto hosts = File("/etc/hosts");
     {
         auto hosts_copy = hosts;
         hosts_copy.tupleof[0].refs = 1; /* uh-oh */
     }
     auto self = File(__FILE__);
     writeln(hosts.rawRead(new char[1000]));
         /* Reads from __FILE__ instead of /etc/hosts. */
}
----

https://run.dlang.io/is/1QSsUk


More information about the Digitalmars-d mailing list