https://issues.dlang.org/show_bug.cgi?id=16652
Issue ID: 16652
Summary: returned rvalue gets destroyed before expressions ends
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
cat > bug.d << CODE
import std.stdio;
struct Vector
{
ubyte[] opSlice()
{
writeln("opslice");
return buf[];
}
~this()
{
writeln("dtor");
}
ubyte[4] buf;
}
void bar(ubyte[])
{
writeln("bar");
}
void main()
{
bar(Vector()[]);
}
CODE
dmd -inline -run bug
---
opslice
dtor <- !!! destroyed
bar <- stale reference
---
The order of evaluation changes when -inline is passed to the compiler. With
that the destructor runs before the function call finishes, thus possibly
passing a stale reference.
Also see https://github.com/rejectedsoftware/vibe.d/pull/1578 and
https://github.com/etcimon/botan/issues/23.
--