D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23306 - @disable new() ought not disable `scope A = new A`
Summary: @disable new() ought not disable `scope A = new A`
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-26 17:21 UTC by Adam D. Ruppe
Modified: 2022-09-06 06:38 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Adam D. Ruppe 2022-08-26 17:21:09 UTC
@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 kinke 2022-08-27 18:25:13 UTC
> @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 Adam D. Ruppe 2022-08-27 18:34:56 UTC
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 RazvanN 2022-09-06 06:38:05 UTC
Fixed by: https://github.com/dlang/dmd/pull/14403