https://issues.dlang.org/show_bug.cgi?id=14618

Walter Bright <bugzi...@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzi...@digitalmars.com

--- Comment #2 from Walter Bright <bugzi...@digitalmars.com> ---
If I prepend:

  @safe:

to the code:

(In reply to ag0aep6g from comment #0)
> struct S
> {
>     immutable(int)* p;
> }
> 
> inout(int)* f(inout S s)
> {
>     inout(int)* result;
>     auto dg = (inout(int)* p) {result = p;};
>     dg(s.p);
>     return result;
> }
> 
> void main()
> {
>     immutable int x = 42;
>     immutable int* p = &x;

   Error: cannot take address of local x in @safe function main

>     assert(*p == 42); /* passes */
>     scope(exit) assert(*p == 42); /* fails */
>     int* m = f(S(p)); /* uh-oh */
>     *m = 13; /* writing over immutable *p */
> }

--

Reply via email to