[Issue 17049] [scope] class references are not escape checked like pointers

2017-02-24 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

--- Comment #7 from Martin Nowak  ---
And this is supposed to not work?

struct Handle { int a; }

static @safe Handle get2(return ref scope S _this)
{
return Handle(1);
}

struct S
{
}

Handle escape() @safe
{
S s;
auto h = s.get2();
return h; // works
}

--


[Issue 17049] [scope] class references are not escape checked like pointers

2017-02-24 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

--- Comment #6 from Martin Nowak  ---
And the same is supposed to work for foreign pointers?

static @safe float* get2(return ref scope S _this)
{
return convert(&_this);
}

@trusted float* convert(S* s) { return cast(float*)s; }

struct S
{
}

float* escape() @safe
{
S s;
auto pf = s.get2();
return pf; // works
}

Error: scope variable pf may not be returned


--


[Issue 17049] [scope] class references are not escape checked like pointers

2017-02-24 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

--- Comment #5 from Martin Nowak  ---
(In reply to Martin Nowak from comment #4)
> return ps1; // works
  silenty escapes !!!
> // return ps2; // doesn't work
  correctly errors on escape !!!
> }

--


[Issue 17049] [scope] class references are not escape checked like pointers

2017-02-24 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

--- Comment #4 from Martin Nowak  ---
There is a difference from member functions to free function.

static @safe S* get2(return ref scope S _this)
{
return &_this;
}

struct S
{
@safe S* get1() return scope
{
return 
}
}

S* escape() @safe
{
S s;
auto ps1 = s.get1();
auto ps2 = s.get2();
return ps1; // works
// return ps2; // doesn't work
}

--


[Issue 17049] [scope] class references are not escape checked like pointers

2017-02-24 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

Martin Nowak  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|INVALID |---

--- Comment #3 from Martin Nowak  ---
Remember how we agreed on that the compiler shouldn't be too smart when
inferring whether the return value could alias any of the arguments.
This is crucial to support ownership idioms such as unique, where the container
could for example just wrap an int handle.
Use-after-free for handles is no different from dangling pointers, just as
unsafe and able to corrupt memory.

struct S
{
float* ptr; // needs a pointer for the compiler to attach the lifetime of
get's return value to S
@safe P get() return scope;
}

P escape() @safe
{
scope S s; // need to explicitly declare this as scope for the compiler to
infer get's return value as scope
P p = s.get();
return p;
}

//

Here is a simpler example on why this is broken.

struct S
{
@safe S* get() return scope
{
return 
}
}

S* escape() @safe
{
S s;
auto ps = s.get();
return ps;
}

In `auto ps = s.get()` the compiler should conservatively assume that ps points
to s, simply b/c the signature (w/ return scope) would allow to do so. Even if
the return type is seemingly unrelated to the passed in scope arguments type
conversions may be done by @trusted functions that are intransparent for the
compiler.

--


[Issue 17049] [scope] class references are not escape checked like pointers

2017-02-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

Walter Bright  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||bugzi...@digitalmars.com
 Resolution|--- |INVALID

--- Comment #2 from Walter Bright  ---
The reason no error is detected is because there isn't one. The declaration:

   S s;

does not declare a pointer that points to the stack.

--


[Issue 17049] [scope] class references are not escape checked like pointers

2017-02-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

--- Comment #1 from Martin Nowak  ---
No longer works (not even for int*) with dmd-master-2017-01-04 and -dip1000.

--


[Issue 17049] [scope] class references are not escape checked like pointers

2016-12-31 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

Martin Nowak  changed:

   What|Removed |Added

   Keywords||safe

--


[Issue 17049] [scope] class references are not escape checked like pointers

2016-12-31 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17049

Martin Nowak  changed:

   What|Removed |Added

   Hardware|x86_64  |All
 OS|Linux   |All
   Severity|enhancement |normal

--