Comment #0 by timothee.cour2 — 2018-02-15T03:45:04Z
```haf
--- main.d
//@nogc: // Error: cannot use operator ~= in @nogc delegate 'main.test.__lambda1'
@nogc // works without the `:`
void test(){
int[2] ret;
static foreach (i; 0 .. 2)
ret[i] = 0;
}
```
related but not dup of https://issues.dlang.org/show_bug.cgi?id=18106 Issue 18106 - @nogc: yields a wrong error where @nogc on each definition does not
Comment #1 by timothee.cour2 — 2018-02-15T03:57:55Z
marked as critical because it prevents top-level `@nogc:` in a module in many cases
Just ran into this myself and was going to file an issue but you beat me to it.
Comment #4 by greensunny12 — 2018-06-27T07:07:06Z
I looked a bit at this and there seem to be two issues going on:
1) DMD creates the __lambda1 member
For this in @nogc main case (i.e. without label), TypeFunction.isnogc = false
-> initInferAttributes tries to infer the attributes of the lambdas and infers it to be not @nogc
For this @nogc: main case (i.e. with the label), TypeFunction.isnogc = true
-> setGC returns true -> failure on CatAssign
2) The __lambda1 uses a CatAssign (probably from CTFE?) and that's checked even though it never makes it to the codegen.
Comment #5 by dlang-bot — 2019-05-30T21:48:36Z
@look-at-me created dlang/dmd pull request #9922 "Fix Issue 18439 Fix issue with `static foreach` not working with scoped @nogc." fixing this issue:
- Fix Issue 18439 Fix issue with `static foreach` not working with scoped @nogc.
https://github.com/dlang/dmd/pull/9922
Comment #6 by dlang-bot — 2019-05-31T01:12:42Z
dlang/dmd pull request #9922 "Fix Issue 18439 Fix issue with `static foreach` not working with scoped @nogc." was merged into stable:
- 0a65ef981578e263a380f6df4668572dce0a52d6 by look-at-me:
Fix Issue 18439 Fix issue with `static foreach` not working with scoped @nogc.
https://github.com/dlang/dmd/pull/9922
Comment #7 by dlang-bot — 2019-06-06T06:04:59Z
dlang/dmd pull request #9984 "Revert "Fix Issue 18439 Fix issue with `static foreach` not working with scoped @nogc."" was merged into stable:
- 76d0babcb454e39bfd420cf5f26faf38ac8b2297 by look-at-me:
Revert "Fix Issue 18439 Fix issue with `static foreach` not working with scoped @nogc."
This reverts commit 0a65ef981578e263a380f6df4668572dce0a52d6.
https://github.com/dlang/dmd/pull/9984
Comment #8 by timon.gehr — 2020-01-16T08:27:27Z
Reopening, as the "fix" has been reverted.
Comment #9 by bugzilla — 2020-02-07T08:52:03Z
For functions, the line is:
sc2.stc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.abstract_ | STC.deprecated_ | STC.override_ |
STC.TYPECTOR | STC.final_ | STC.tls | STC.gshared | STC.ref_ | STC.return_ | STC.property |
STC.nothrow_ | STC.pure_ | STC.safe | STC.trusted | STC.system);
https://github.com/dlang/dmd/blob/master/src/dmd/semantic3.d#L316
Interestingly, @nogc does flow through here.
Comment #10 by dlang-bot — 2020-03-01T07:40:26Z
@looked-at-me created dlang/dmd pull request #10851 "fix issue 18439" fixing this issue:
- fixes issue 18439 remove attributes applied to hidden lambda used in static foreach
https://github.com/dlang/dmd/pull/10851
Comment #11 by robert.schadek — 2024-12-13T18:57:07Z