Bug 18484 – [dip1000] Subtype allows reference to escape with implicit casting
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2018-02-21T15:37:34Z
Last change time
2018-03-16T03:02:06Z
Keywords
safe
Assigned to
No Owner
Creator
Radu Racariu
Comments
Comment #0 by radu.racariu — 2018-02-21T15:37:34Z
Compile the following with dmd 2.079-beta1 (older compilers behave the same) and -dip1000:
================================
struct S
{
@property char[] c() return
{
return i.c;
}
alias c this;
static struct I
{
char[] c;
}
I* i;
}
char[] c()
{
auto x = S();
return x;
}
===========================
Produces a nice error:
Error: returning x.c() escapes a reference to local variable x
Now change 'c' function to this
===========================
char[] c()
{
return S();
}
===========================
No error is reported.
Expected to see the same error.
Comment #1 by bugzilla — 2018-03-15T05:07:51Z
Much reduced test case:
---
struct S
{
int* bar() return;
}
int* test1()
{
auto x = S(); return x.bar(); // error
}
int* test2()
{
return S().bar(); // no error
}