Bug 23306 – @disable new() ought not disable `scope A = new A`

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-08-26T17:21:09Z
Last change time
2022-09-06T06:38:05Z
Assigned to
No Owner
Creator
Adam D. Ruppe

Comments

Comment #0 by destructionator — 2022-08-26T17:21:09Z
@disable new can be used to disable the `new` operator on a thing so it isn't accidentally GC managed, which is liable to cause trouble with destructor/finalizer confusion. But it currently disables scope too: ``` class A { @disable new(); } void main() { scope A a = new A(); } ``` scopeclass.d(6): Error: cannot allocate `class A` with `new` because it is annotated with `@disable new()` The purpose of disabling `new` is not the presence of the keyword per se, it has more to do with lifetime management. Like I said, it is about a destructor that needs to be called in a particular way every time I use it. `scope` solves this. So I propose that `scope x = new` be exempt from the `@disable new` check.
Comment #1 by kinke — 2022-08-27T18:25:13Z
> @disable new can be used to disable the `new` operator on a thing so it isn't accidentally GC managed Oh wow, never seen that and haven't found it in the spec... ?
Comment #2 by destructionator — 2022-08-27T18:34:56Z
It has been there since the beginning. The spec PR got stalled and closed though https://github.com/dlang/dlang.org/pull/2846/files
Comment #3 by razvan.nitu1305 — 2022-09-06T06:38:05Z