Thread overview
[Issue 17174] auto ref allows pointers to rvalues
Feb 10, 2017
Alex
[Issue 17174] can take address of member of struct parameter in @safe code
Feb 10, 2017
ag0aep6g@gmail.com
Feb 11, 2017
Alex
Mar 04, 2018
Walter Bright
February 10, 2017
https://issues.dlang.org/show_bug.cgi?id=17174

Alex <sascha.orlov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sascha.orlov@gmail.com

--
February 10, 2017
https://issues.dlang.org/show_bug.cgi?id=17174

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, safe
                 CC|                            |ag0aep6g@gmail.com
           Hardware|x86                         |All
            Summary|auto ref allows pointers to |can take address of member
                   |rvalues                     |of struct parameter in
                   |                            |@safe code
                 OS|Mac OS X                    |All

--- Comment #1 from ag0aep6g@gmail.com ---
Taking the address of a value parameter is allowed in @system code. Your constructor is not marked as @safe, so it's @system and you're allowed to do that.

However, if you add @safe, the code still compiles. That's a bug. It doesn't seem to be related to `auto ref`, though. Rather, the compiler gets confused by the struct. I'm changing the summary of this issue to be about this.

----
/* Shouldn't compile: */
void f(initStruct iS) @safe
{
    auto p = &iS.var; /* Should trigger the same error as below. */
}

struct initStruct
{
    size_t var;
}

/* Doesn't compile, as it should be: */
void g(size_t var) @safe
{
    auto p = &var; /* "Error: cannot take address of parameter" */
}
----

--
February 11, 2017
https://issues.dlang.org/show_bug.cgi?id=17174

--- Comment #2 from Alex <sascha.orlov@gmail.com> ---
@ag0aep6g
Ok... my complaint was about your first two lines. Didn't take this into
account.
But even then, it seems strange to me to be able to take a pointer to a value
parameter, in any case...
With other words:
The treatment I was wondering about (allocating memory) is needed, and I should
have known this, because the constructor is not marked as @safe.

--
March 04, 2018
https://issues.dlang.org/show_bug.cgi?id=17174

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|---                         |INVALID

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
With -dip1000, both functions pass, because taking the address is allowed, you just cannot escape the address.

--