← Back to index
|
Original Bugzilla link
Bug 15191 – DIP25: Taking address of ref return is not type checked soundly
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-12T10:08:00Z
Last change time
2016-10-01T11:48:03Z
Keywords
pull, safe
Assigned to
nobody
Creator
timon.gehr
Comments
Comment #0
by timon.gehr — 2015-10-12T10:08:40Z
The following code corrupts memory: enum N=100; ref int[N] foo(return ref int[N] s)@safe{ return s; } int[N]* bar(return ref int[N] s)@safe{ return &foo(s); } ref int[N] baz()@safe{ int[N] s; return *bar(s); } void bang(ref int[N] x)@safe{ x[]=0x25BAD; } void main()@safe{ bang(baz()); }
Comment #1
by bugzilla — 2016-06-30T05:44:17Z
Reformatting for readability: enum N=100; ref int[N] foo(return ref int[N] s)@safe { return s; } int[N]* bar(return ref int[N] s) @safe { return &foo(s); } ref int[N] baz()@safe { int[N] s; return *bar(s); } void bang(ref int[N] x) @safe { x[]=0x25BAD; } void main() @safe { bang(baz()); }
Comment #2
by bugzilla — 2016-06-30T05:48:41Z
The trouble here is the following: int[N]* bar(return ref int[N] s) @safe { return &foo(s); // <== taking the address of a reference should be an error }
Comment #3
by bugzilla — 2016-06-30T06:14:17Z
Not really an error with -dip25, as the diagnostic message should appear regardless of -dip25 or not.
https://github.com/dlang/dmd/pull/5892
Comment #4
by github-bugzilla — 2016-06-30T23:47:55Z
Commits pushed to master at
https://github.com/dlang/dmd
https://github.com/dlang/dmd/commit/7e057ad1a5dfb86b3cc2d3ba7167c44c053c0253
fix Issue 15191 - DIP25: Taking address of ref return is not type checked soundly
https://github.com/dlang/dmd/commit/c9e42913421dcaf1b7202a91b237b598b3600d48
Merge pull request #5892 from WalterBright/fix15191 fix Issue 15191 - DIP25: Taking address of ref return is not type cheā¦
Comment #5
by github-bugzilla — 2016-10-01T11:48:03Z
Commits pushed to stable at
https://github.com/dlang/dmd
https://github.com/dlang/dmd/commit/7e057ad1a5dfb86b3cc2d3ba7167c44c053c0253
fix Issue 15191 - DIP25: Taking address of ref return is not type checked soundly
https://github.com/dlang/dmd/commit/c9e42913421dcaf1b7202a91b237b598b3600d48
Merge pull request #5892 from WalterBright/fix15191