Continuation passing style vs. wrapper objects in dmd

Dennis dkorpel at gmail.com
Tue May 25 17:56:39 UTC 2021


On Tuesday, 25 May 2021 at 17:21:16 UTC, Andrei Alexandrescu 
wrote:
> int i = stat(stringz(name).ptr, &statbuf));

I much prefer that form too, but unfortunately it only works with 
immediate use. This is a big pitfall:
```D
{
const(char)* s = stringz(name).ptr;
// destructor runs here
printf(s); // use after free
}
```

You have to write:
```D
{
auto temp = stringz(name);
const(char)* s = temp.ptr;
printf(s); // good!
// destructor runs here
}

```

The first form should be preventable with -dip1000, but it isn't 
currently:
https://issues.dlang.org/show_bug.cgi?id=20880
https://issues.dlang.org/show_bug.cgi?id=21868


More information about the Digitalmars-d mailing list