dmd
dmd copied to clipboard
escaping sliced stack arrays not detected
Walter Bright (@WalterBright) reported this on 2024-09-07T21:43:13Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=24750
CC List
- Jonathan M Davis (@jmdavis)
- Nick Treleaven (@ntrel)
Description
Jonathan Davis reports:
int[] foo()
{
int[3] arr = [1,2,3];
return arr[]; // returning `arr[]` escapes a reference to local variable `arr`
}
whereas:
int[] foo()
{
int[3] arr = [1,2,3];
int[] slice = arr[];
return slice;
}
compiles without complaint.