dmd icon indicating copy to clipboard operation
dmd copied to clipboard

escaping sliced stack arrays not detected

Open dlangBugzillaToGithub opened this issue 1 year ago • 11 comments

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.

dlangBugzillaToGithub avatar Sep 07 '24 21:09 dlangBugzillaToGithub