Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@nogc: yields a wrong error where @nogc on each definition does not #19351

Open
dlangBugzillaToGithub opened this issue Dec 20, 2017 · 6 comments

Comments

@dlangBugzillaToGithub
Copy link

Eyal reported this on 2017-12-20T09:53:08Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18106

CC List

  • Ketmar Dark

Description

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); }); }
@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 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.

@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 2017-12-20T13:35:28Z

`return new int(5);`, of course, sorry.

@dlangBugzillaToGithub
Copy link
Author

eyal commented on 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); }); } }

@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 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.

@dlangBugzillaToGithub
Copy link
Author

eyal commented on 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.

@dlangBugzillaToGithub
Copy link
Author

timon.gehr commented on 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant