[Issue 3925] Missed escaping reference of a local variable

2018-04-21 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3925

Nick Treleaven  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||n...@geany.org
 Resolution|--- |FIXED

--- Comment #8 from Nick Treleaven  ---
All code samples here fail to compile with @safe and -dip1000, dmd v2.079.1,
except this one:

(In reply to Michel Fortin from comment #3)
> There is a similar problem with delegates:

I looked to see if this is filed, the closest I could find is Issue 18738,
which is strongly related. Closing this.

--


[Issue 3925] Missed escaping reference of a local variable

2011-06-29 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3925



--- Comment #7 from bearophile_h...@eml.cc 2011-06-29 15:32:18 PDT ---
Two more cases of undetected escaping of reference:


int* ptr;
void foo1() {
int local;
ptr = &local;
}
void foo2(int** x) {
int i;
*x = &i;
}
void main() {}


See also bug 5541 and bug 1313

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3925] Missed escaping reference of a local variable

2010-10-25 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3925



--- Comment #6 from bearophile_h...@eml.cc 2010-10-25 15:40:48 PDT ---
(In reply to comment #5)
> ---
> class A{}
> 
> A foo(A a)
> {
> return a;
> }
> 
> A bar()
> {
> scope A a=new A();
> return foo(a);
> }
> ---

The "scope" is deprecated, so I think yours isn't a valid error case, sorry :-(

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3925] Missed escaping reference of a local variable

2010-10-25 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3925



--- Comment #5 from Sobirari Muhomori  2010-10-25 
13:59:45 PDT ---
---
class A{}

A foo(A a)
{
return a;
}

A bar()
{
scope A a=new A();
return foo(a);
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3925] Missed escaping reference of a local variable

2010-10-22 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3925



--- Comment #4 from bearophile_h...@eml.cc 2010-10-22 19:26:06 PDT ---
Here DMD 2.049 doesn't find the error, but it should:


int* foo() {
int x;
int* p = &x;
return p;
}
void main() {}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3925] Missed escaping reference of a local variable

2010-03-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3925


Michel Fortin  changed:

   What|Removed |Added

 CC||michel.for...@michelf.com


--- Comment #3 from Michel Fortin  2010-03-10 
15:04:05 EST ---
(In reply to comment #2)
> I've just been dealing with ref returns in my recent CTFE patch. But I don't
> think it's very complicated.
> As far as I can tell, ref returns are only a problem if a local variable is
> passed as a ref parameter, or if it is a member function of a local struct.
> If either of those is true, it should be considered to potentially be a return
> of a local variable.
> I don't think there's any problem with foo, but bar should generate an error.

This seems fair. There is a similar problem with delegates:

@safe
void delegate() foo(ref int a) {
return { writeln(a); };
}

@safe
void delegate() bar() {
int a;
return foo(a); // leaking reference to a beyound bar's scope
}

It could be solved in the same way.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3925] Missed escaping reference of a local variable

2010-03-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3925


Don  changed:

   What|Removed |Added

 CC||clugd...@yahoo.com.au


--- Comment #2 from Don  2010-03-10 11:12:03 PST ---
(In reply to comment #1)
> This was the original code by Michel Fortin:
> 
> @safe ref int foo(ref int a) {
> return a;
> }
> @safe ref int bar() {
> int a;
> return foo(a);
> }
> 
> 
> Norbert Nemec comments:
> >I would say the possibility of a bug makes this code unsafe by definition. 
> >Ref returns must be considered unsafe by default, unless the compiler can 
> >know for sure that the object will exist beyond the lifetime of the 
> >function.<
> 
> 
> So I think Norbert Nemec idea is: while the normal compiler error messages
> assume correctness and need a demonstration of unsafety to be shown, @safe can
> do the opposite assuming unsafety and requiring a demonstration of safety.

I've just been dealing with ref returns in my recent CTFE patch. But I don't
think it's very complicated.
As far as I can tell, ref returns are only a problem if a local variable is
passed as a ref parameter, or if it is a member function of a local struct.
If either of those is true, it should be considered to potentially be a return
of a local variable.
I don't think there's any problem with foo, but bar should generate an error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3925] Missed escaping reference of a local variable

2010-03-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3925



--- Comment #1 from bearophile_h...@eml.cc 2010-03-10 10:08:04 PST ---
This was the original code by Michel Fortin:

@safe ref int foo(ref int a) {
return a;
}
@safe ref int bar() {
int a;
return foo(a);
}


Norbert Nemec comments:
>I would say the possibility of a bug makes this code unsafe by definition. Ref 
>returns must be considered unsafe by default, unless the compiler can know for 
>sure that the object will exist beyond the lifetime of the function.<


So I think Norbert Nemec idea is: while the normal compiler error messages
assume correctness and need a demonstration of unsafety to be shown, @safe can
do the opposite assuming unsafety and requiring a demonstration of safety.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---