"Fossies" - the Fresh Open Source Software Archive

Member "dmd-2.089.0/test/fail_compilation/fail19965.d" (2 Nov 2019, 498 Bytes) of package /linux/misc/dmd-2.089.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) D source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2 REQUIRED_ARGS: -preview=dip1000
    3 TEST_OUTPUT:
    4 ---
    5 fail_compilation/fail19965.d(36): Error: address of variable `f` assigned to `a` with longer lifetime
    6 ---
    7 */
    8 
    9 // https://issues.dlang.org/show_bug.cgi?id=19965
   10 
   11 struct Buffer
   12 {
   13     int[10] data;
   14 
   15     int[] getData() @safe return
   16     {
   17         return data[];
   18     }
   19 }
   20 
   21 struct Foo()
   22 {
   23     Buffer buffer;
   24 
   25     int[] toArray() @safe return
   26     {
   27         return buffer.getData;
   28     }
   29 }
   30 
   31 int[] a;
   32 
   33 void main() @safe
   34 {
   35     Foo!() f;
   36     a = f.toArray;
   37 }