digitalmars.D.learn - Escaping address of
- Nick Treleaven (12/12) Apr 11 2018 Is this a known bug? With v2.079.0, with or without -dip1000:
- Jonathan M Davis (14/26) Apr 11 2018 Without -dip1000, @safe code specifically disallows & on local variables...
- Uknown (5/6) Apr 11 2018 Adding a destructor makes the compiler return an error about
- Nick Treleaven (3/5) Apr 12 2018 Thanks. Filed, mentioning this:
Is this a known bug? With v2.079.0, with or without -dip1000:
safe unittest
{
struct S
{
int i;
}
auto p = &S().i;
}
The address of field `i` should not escape, right? It's also
incorrectly allowed when using an lvalue of S (when -dip1000 is
not present).
Apr 11 2018
On Wednesday, April 11, 2018 16:08:06 Nick Treleaven via Digitalmars-d-learn
wrote:
Is this a known bug? With v2.079.0, with or without -dip1000:
safe unittest
{
struct S
{
int i;
}
auto p = &S().i;
}
The address of field `i` should not escape, right? It's also
incorrectly allowed when using an lvalue of S (when -dip1000 is
not present).
Without -dip1000, safe code specifically disallows & on local variables.
Beyond that, I'm not sure. Arguably, it should disallow it entirely, though
if the compiler can guarantee that the address is on the heap, then it's
probably fine. However, IMHO, regardless of safe or DIP 1000, your example
should not be legal period. It's taking the address of the field of a
temporary, which is _never_ a valid thing to do, safe or not. I guess that
the compiler isn't smart enough to figure out that that's what's going on,
since it's i itself that it's getting the address for and not the temporary
directly, but even if it can't be smart enough for some reason to figure out
that what's going on here is never okay, that & should still be system,
since it's not taking the address of something on the heap.
- Jonathan M Davis
Apr 11 2018
On Wednesday, 11 April 2018 at 16:25:20 UTC, Jonathan M Davis wrote:[...]Adding a destructor makes the compiler return an error about lifetimes, with or without -dip1000 https://run.dlang.io/is/ddXqNu
Apr 11 2018
On Thursday, 12 April 2018 at 00:32:49 UTC, Uknown wrote:Adding a destructor makes the compiler return an error about lifetimes, with or without -dip1000Thanks. Filed, mentioning this: https://issues.dlang.org/show_bug.cgi?id=18756
Apr 12 2018








Nick Treleaven <nick geany.org>