Bug 18106 – @nogc: yields a wrong error where @nogc on each definition does not

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-12-20T09:53:08Z
Last change time
2024-12-13T18:55:40Z
Assigned to
No Owner
Creator
Eyal
Moved to GitHub: dmd#19351 →

Comments

Comment #0 by eyal — 2017-12-20T09:53:08Z
This compiles correctly: auto ignoreDlg(void function() dlg) {} @nogc void foo() { ignoreDlg({ new int(5); }); } But this gives an incorrect error about the "new" violating @nogc: auto ignoreDlg(void function() dlg) {} @nogc: void foo() { ignoreDlg({ new int(5); }); }
Comment #1 by ketmar — 2017-12-20T13:34:43Z
it's not *technically* incorrect: `@nogc:` affects *all* followind definitions, including lambdas. thus, in the second case, we actually have `auto __lambda () @nogc { new int(5); }`, and compiler complains.
Comment #2 by ketmar — 2017-12-20T13:35:28Z
`return new int(5);`, of course, sorry.
Comment #3 by eyal — 2017-12-20T15:39:07Z
It does not affect other kinds of nested scopes. For example, this does compile: auto ignoreDlg(void function() dlg) {} @nogc: struct S { void foo() { ignoreDlg(() { new int(5); }); } }
Comment #4 by ketmar — 2017-12-20T15:47:27Z
yes, `struct` (and `class`, i believe) isn't affected. outer @nogc for *struct* (and class) doesn't change member attrs, only inner @nogc does. this is the logic compiler applies. ;-) i'm still not sure if `@nogc` should do the same thing as `@nogc:` or not, tho. it prolly should, but let's wait for some compiler dev to clarify the things.
Comment #5 by eyal — 2017-12-20T16:31:09Z
It makes no sense at all for "@nogc" to apply to statements within a statement block of a function. It would only make sense if it applied recursively to *all* nested scopes.
Comment #6 by timon.gehr — 2019-06-05T22:40:52Z
This is a more general problem, applying to other function attributes as well as @nogc. The pull request below should be reverted as soon as this issue is fixed (it is an ugly hack fixing the problem only for the `static foreach` lowering and only for @nogc): https://github.com/dlang/dmd/pull/9922/commits/0a65ef981578e263a380f6df4668572dce0a52d6
Comment #7 by robert.schadek — 2024-12-13T18:55:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19351 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB