Bug 17422 – [scope] class reference not initialized as scope variable

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-05-23T21:50:00Z
Last change time
2017-08-07T13:16:21Z
Keywords
safe
Assigned to
bugzilla
Creator
code

Comments

Comment #0 by code — 2017-05-23T21:50:17Z
cat > bug.d << CODE struct RC { Object get() return scope @trusted { return cast(Object) &store[0]; } private: ubyte[__traits(classInstanceSize, Object)] store; } Object test() @safe { RC rc; auto p = rc.get; // p must be inferred as scope variable, works for int* return p; } CODE dmd -c bug -dip1000 Should raise an error but doesn't get catched by the compiler.
Comment #1 by bugzilla — 2017-05-25T04:36:37Z
Comment #2 by github-bugzilla — 2017-06-14T21:57:48Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ad041aa29e02ed1cca2d00f2553ac16a86762bfa fix Issue 17422 - class reference not initialized as scope variable - infer scope for class references to prevent escaping - those are just normal class references with scope to prevent escaping - only `scope o = new Object` remains special, because it uses the fact that the class ref cannot be escaped to allocate the instance on the stack https://github.com/dlang/dmd/commit/6ad2e6d91b84a00703900c2b6e3a9e9ab03f1e6b Merge pull request #6826 from MartinNowak/fix17422 [scope] fix Issue 17422 - class reference not initialized as scope variable
Comment #3 by github-bugzilla — 2017-08-07T13:16:21Z
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ad041aa29e02ed1cca2d00f2553ac16a86762bfa fix Issue 17422 - class reference not initialized as scope variable https://github.com/dlang/dmd/commit/6ad2e6d91b84a00703900c2b6e3a9e9ab03f1e6b Merge pull request #6826 from MartinNowak/fix17422