memory safety checks and trust
Johan
j at j.nl
Sat Apr 11 10:01:01 UTC 2020
On Saturday, 11 April 2020 at 02:57:03 UTC, Walter Bright wrote:
> On 4/10/2020 6:21 PM, Adam D. Ruppe wrote:
>> ```
>> void main() {
>> int a;
>> b ~= &a;
>> }
>>
>> int*[] b;
>> ```
>>
>> trust.d(3): Error: copying & a into allocated memory escapes a
>> reference to local variable a
>>
>>
>> (Interestingly, `b = [&a]` instead of ~= passes muster. What's
>> the difference? Just another bug in this?)
>
> You will get the error with -preview=dip1000. Since that will
> eventually be the default, it's not a bug.
>
> You can get it to pass without error with the following:
>
> @system int* foo(int* p) { return p; }
>
> @system void test() {
> int a;
> b ~= &a;
> b ~= [foo(&a)];
> }
>
> int*[] b;
The OP's point was that exactly this does not compile. Trivial to
test online:
https://d.godbolt.org/z/i8WFcs
-Johan
More information about the Digitalmars-d
mailing list