[Issue 23306] New: @disable new() ought not disable `scope A = new A`

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 26 17:21:09 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23306

          Issue ID: 23306
           Summary: @disable new() ought not disable `scope A = new A`
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: destructionator at gmail.com

@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.

--


More information about the Digitalmars-d-bugs mailing list