Compiler bug or incorrect usage for pointer of Struct?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Jan 13 14:11:23 UTC 2018
On Sat, Jan 13, 2018 at 12:22:17PM +0000, Heromyth via Digitalmars-d wrote:
[...]
> auto writerFor(OutRange)(auto ref OutRange outRange)
> {
> auto res = Writer!(OutRange)();
> res.setSink(outRange);
> return res;
> }
>
> struct Writer(OutRange)
> {
> private OutRange* output;
>
> void setSink(ref OutRange output)
> {
> this.output = &output;
[...]
Here's the bug. `output` refers to a local variable (parameter) in
writerFor(), which goes out of scope after writerFor() exits, so
this.output becomes a dangling pointer.
T
--
Public parking: euphemism for paid parking. -- Flora
More information about the Digitalmars-d
mailing list