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 }
Comment #2 by bugzilla — 2018-03-15T05:41:57Z
Comment #3 by github-bugzilla — 2018-03-16T03:02:05Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ff6edd1f56da1604d0b22d5342c5100633551cce fix Issue 18484 - [dip1000] Subtype allows reference to escape with implicit casting https://github.com/dlang/dmd/commit/03eb2b7c0a8c0bbd0e01ab4b1b24cb30d82f4d02 Merge pull request #8036 from WalterBright/fix18484 fix Issue 18484 - [dip1000] Subtype allows reference to escape with i… merged-on-behalf-of: Walter Bright <[email protected]>