Bug 17892 – Scope analysis with -dip1000 fails for templated structs

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-10T22:29:48Z
Last change time
2018-03-12T06:12:59Z
Keywords
safe
Assigned to
No Owner
Creator
Per Nordlöw

Comments

Comment #0 by per.nordlow — 2017-10-10T22:29:48Z
When struct S { @safe: int[ 128] x; scope ref int front() return { return x[ 0]; } scope int* pointer() return { return &x[ 0]; } } ref int testFront() { S s; return s.front(); // error } int* testPointer() { S s; return s.pointer(); // error } is turned into a template @safe: struct ST( T) { @safe: T[ 128] x; scope ref T front() return { return x[ 0]; } scope T* pointer() return { return &x[ 0]; } } scope analysis (with -dip1000) no longer forbids escaping of reference and pointer as in ref int testFrontT() { ST!int s; return s.front(); // reference to stack element escapes } int* testPointerT() { ST!int s; return s.pointer(); // pointer to stack element escapes }
Comment #1 by bugzilla — 2018-03-10T09:06:04Z
Comment #2 by github-bugzilla — 2018-03-11T07:12:23Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/1ec125e6bc5f7aec460d5d7deb2699d92f473c5c fix Issue 17892 - Scope analysis with -dip1000 fails for templated structs https://github.com/dlang/dmd/commit/37688254c7663c017b5f2b9be2bfcbca3070fbfa Merge pull request #7993 from WalterBright/fix17892 fix Issue 17892 - Scope analysis with -dip1000 fails for templated st… merged-on-behalf-of: Walter Bright <[email protected]>
Comment #3 by github-bugzilla — 2018-03-12T06:12:59Z