Jump to page: 1 2
Thread overview
[Issue 19175] @safe code can escape local array references
Aug 17, 2018
Peter Alexander
Aug 17, 2018
Jonathan M Davis
Aug 17, 2018
Mike Franklin
Aug 17, 2018
Peter Alexander
Aug 21, 2018
Seb
Aug 21, 2018
anonymous4
Aug 21, 2018
anonymous4
Aug 26, 2018
Radu Racariu
Aug 27, 2018
anonymous4
Aug 27, 2018
ag0aep6g
Aug 22, 2019
Mike Franklin
Aug 22, 2019
ag0aep6g
August 17, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

Peter Alexander <peter.alexander.au@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid

--
August 17, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

Jonathan M Davis <issues.dlang@jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang@jmdavisProg.co
                   |                            |m

--- Comment #1 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
This is a duplicate of https://issues.dlang.org/show_bug.cgi?id=8838, which was closed as fixed based on the fact that -dip1000 fixes the problem. It's still quite broken without -dip1000 though.

--
August 17, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe
                 CC|                            |slavo5150@yahoo.com

--
August 17, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

--- Comment #2 from Peter Alexander <peter.alexander.au@gmail.com> ---
It is still broken with -dip1000

https://run.dlang.io/is/gJi2Fa

--
August 21, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

Seb <greensunny12@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12@gmail.com

--
August 21, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

--- Comment #3 from anonymous4 <dfj1esp02@sneakemail.com> ---
Reduced:

@safe:

struct A(alias fun)
{
    int[] r;
    this(int[] q){r=q;}
}

template m(alias fun)
{
    auto m(int[] r)
    {
        return A!fun(r);
    }
}

auto foo() {
  int[6] xs = [0, 1, 2, 3, 4, 5];
  return xs[].m!(x => x);
}

void main() {
  auto a=foo();
}

--
August 21, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

--- Comment #4 from anonymous4 <dfj1esp02@sneakemail.com> ---
@safe:

struct A(T)
{
    int[] r;
    this(int[] q){r=q;}
}

int[] escape(T)(int[] r)
{
    return A!int(r).r;
}

int[] f()
{
    int[6] xs = [0, 1, 2, 3, 4, 5];
    return xs.escape!int;
}

--
August 26, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

Radu Racariu <radu.racariu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |radu.racariu@gmail.com

--- Comment #5 from Radu Racariu <radu.racariu@gmail.com> ---
Under dip1000, what I think is that slicing a static array should always be considered scope.

Also, calling a functions with a scope slice with the parameter for the slice not annotated as scope should result in an error if the compiler can't prove that the parameter can't escape.

--
August 27, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

--- Comment #6 from anonymous4 <dfj1esp02@sneakemail.com> ---
Same for pointers:

@safe:

struct A(T)
{
    int* r;
    this(int* q){r=q;}
}

int* escape(T)(int* r)
{
    return A!int(r).r;
}

int* f()
{
    int x;
    return escape!int(&x);
}

--
August 27, 2018
https://issues.dlang.org/show_bug.cgi?id=19175

ag0aep6g <ag0aep6g@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g@gmail.com

--- Comment #7 from ag0aep6g <ag0aep6g@gmail.com> ---
(In reply to anonymous4 from comment #6)
> Same for pointers:
[...]

Resolving the templates shows that this is related to `pure`:

----
@safe:

struct A
{
    int* r;
    this(int* q) pure { r = q; }
}

int* escape(int* r) pure
{
    return A(r).r;
}

int* f()
{
    int x;
    return escape(&x);
}
----

--
« First   ‹ Prev
1 2