Re: Escaping address of

2018-04-12 Thread Nick Treleaven via Digitalmars-d-learn

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 -dip1000


Thanks. Filed, mentioning this:
https://issues.dlang.org/show_bug.cgi?id=18756


Re: Escaping address of

2018-04-11 Thread Uknown via Digitalmars-d-learn
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


Re: Escaping address of

2018-04-11 Thread Jonathan M Davis via Digitalmars-d-learn
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 = ().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



Escaping address of

2018-04-11 Thread Nick Treleaven via Digitalmars-d-learn

Is this a known bug? With v2.079.0, with or without -dip1000:

@safe unittest
{
struct S
{
int i;
}
auto p = ().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).