D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15824 - 'scope' attribute ignored when making an alias to a scope delegate
Summary: 'scope' attribute ignored when making an alias to a scope delegate
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-23 14:48 UTC by Mathias Lang
Modified: 2020-08-04 04:24 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias Lang 2016-03-23 14:48:01 UTC
The following code fails to compile:

```
alias scope void delegate() AltDg;

void foo (AltDg dg) @nogc {}
void main () @nogc {
    uint i;
    foo(() { i = 1; });
}
```

Error message:
`foo.d(4): Error: function D main @nogc function allocates a closure with the GC`

Using `void foo (scope AltDg dg) @nogc {}` works fine.
Comment 1 Martin Nowak 2017-05-23 21:53:27 UTC
As scope is a storage class, it cannot be part of a type or alias declaration, i.e. just like ref you can add it for parameters and unlike ref, scope can be used on variable declarations.
Comment 2 Martin Nowak 2017-05-23 21:54:27 UTC
It should possibly be made an error to declare such aliases.
Comment 3 Mathias LANG 2020-08-04 04:24:20 UTC
https://github.com/dlang/dmd/pull/10018 deprecated this.