[Issue 19721] Cannot take address of scope local variable even with dip1000 if a member variable is a delegate
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 4 08:01:30 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=19721
Walter Bright <bugzilla at digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Hardware|x86_64 |All
Resolution|--- |INVALID
OS|Linux |All
--- Comment #3 from Walter Bright <bugzilla at digitalmars.com> ---
Here's what's happening. `scope int* s;` declares `s` as a pointer that must
not be allowed to escape `main()`. The `func(&s);` passes the address of `s` to
`func`. `func` declares its parameter as `scope int**`. This ensures that the
address of `s` does not escape, but says nothing about `s`'s pointer value,
which must not be allowed to escape. I.e. the value of `s` is not protected
from escaping `func`, so the call causes a compile error.
If `s` is simply declared as an `int`, the `scope` annotation for `s` is
meaningless, as there is no pointer value to protect, and it compiles
successfully.
----
Generally, rewriting perplexing examples as simple pointers tends to make what
is happening much easier to determine. A delegate is regarded as a pointer. A
struct that contains pointer values is itself regarded as a pointer. Hence the
simplification of the example.
--
More information about the Digitalmars-d-bugs
mailing list