Bug 3032 – No stack allocation for "scope c = new class Object {};"

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-05-27T09:22:00Z
Last change time
2015-06-09T05:11:40Z
Keywords
performance, pull, rejects-valid
Assigned to
nobody
Creator
fvbommel

Comments

Comment #0 by fvbommel — 2009-05-27T09:22:48Z
(Found in 1.045, but that isn't in the version list) In the following code 'bar' is heap-allocated even though it's "scope bar = new ...": ----- void foo() { scope bar = new class Object {}; // on heap } ----- If the class is given a name then it's stack-allocated: ----- void foo() { class Anon : Object {} scope bar = new Anon; // on stack } ----- (Look at the disassembled output to see the difference)
Comment #1 by k.hara.pg — 2014-05-27T08:11:16Z
In D2 git-head, @nogc attribute should accept such stack allocation of anonymous class. void foo() @nogc { scope bar = new class Object {}; // should be allowed } D2 fix: https://github.com/D-Programming-Language/dmd/pull/3593
Comment #2 by bearophile_hugs — 2014-05-27T09:14:45Z
(In reply to Kenji Hara from comment #1) > In D2 git-head, @nogc attribute should accept such stack allocation of > anonymous class. > > void foo() @nogc { > scope bar = new class Object {}; // should be allowed > } > > D2 fix: > https://github.com/D-Programming-Language/dmd/pull/3593 But isn't such usage of "scope" deprecated for D2?
Comment #3 by k.hara.pg — 2014-05-27T10:42:42Z
(In reply to bearophile_hugs from comment #2) > But isn't such usage of "scope" deprecated for D2? It's not yet deprecated.
Comment #4 by github-bugzilla — 2014-05-27T17:11:00Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/abc7033bf9cf7f7224a47e45096efc48a21b5ab8 fix Issue 3032 - No stack allocation for "scope c = new class Object {};" https://github.com/D-Programming-Language/dmd/commit/9d48c47fe1927282de8c80730c42527a6d029b15 Merge pull request #3593 from 9rnsr/fix3032 Issue 3032 - No stack allocation for "scope c = new class Object {};"