[Issue 3024] Array slicing allows returning an escaping reference to a local stack variable

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

Nick Treleaven  changed:

   What|Removed |Added

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

--- Comment #3 from Nick Treleaven  ---
(In reply to david from comment #0)
> byte[] func2()
> {
>   byte[16] v= [65,65,65,65,
>65,65,65,65,
>65,65,65,65,
>65,65,65,65];
>   return v[0..16];
> }

This is now fixed (dmd v2.079.1):

onlineapp.d(7): Error: returning v[0..16] escapes a reference to local variable
v

--


[Issue 3024] Array slicing allows returning an escaping reference to a local stack variable

2009-07-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3024


Matti Niemenmaa matti.niemenmaa+dbugzi...@iki.fi changed:

   What|Removed |Added

   Platform|x86 |All
Version|2.028   |1.045
Summary|array slicing bypass the|Array slicing allows
   |stack var escape check  |returning an escaping
   ||reference to a local stack
   ||variable
 OS/Version|Windows |All




--- Comment #2 from Matti Niemenmaa matti.niemenmaa+dbugzi...@iki.fi  
2009-07-12 08:53:14 PDT ---
Also affects 1.0.

It's true that the specs don't mention it but it's a bit inconsistent that both
the pointer and scope object cases are detected while the case of array slicing
isn't. Of the following, currently only the first three result in a compile
error:

int*   pointer() { int x;  return x;   }
Object object()  { scope Object x; return  x;   }
int[]  array()   { int[1] x;   return  x;   }
int[]  slice()   { int[1] x;   return  x[]; }

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