memcpy() comparison: C, Rust, and D

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 31 15:41:46 PST 2017


On 1/31/2017 12:00 PM, Mathias Lang wrote:
> *Can* make use of it... But won't.
> Any code calling memcpy has to be in a @trusted wrapper, in which `return scope`
> is not checked.
> So adding `return scope` annotations to non-safe D binding is just like adding
> documentation. Which is on par with what C is doing, in the end.


----
import core.stdc.string;

void* foo()
{
     char[10] d;
     char[10] s;
     return memcpy(&d[0], &s[0], 10); // Error: escaping reference to local 
variable d
}
----

There was a bit of discussion about this a while back. The result was we agreed 
to not break existing NOT BROKEN code with the new escape detection feature. The 
above code is broken, and so is diagnosed regardless of -dip1000 settings, 
@safe, @trusted or @system attributes.


More information about the Digitalmars-d mailing list