diff options
Diffstat (limited to 'gcc/testsuite/gdc.test/fail_compilation/retscope.d')
-rw-r--r-- | gcc/testsuite/gdc.test/fail_compilation/retscope.d | 87 |
1 files changed, 57 insertions, 30 deletions
diff --git a/gcc/testsuite/gdc.test/fail_compilation/retscope.d b/gcc/testsuite/gdc.test/fail_compilation/retscope.d index 35efda38ac3..58f0430f5ad 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/retscope.d +++ b/gcc/testsuite/gdc.test/fail_compilation/retscope.d @@ -1,14 +1,13 @@ /* -REQUIRED_ARGS: -dip1000 -PERMUTE_ARGS: +REQUIRED_ARGS: -preview=dip1000 TEST_OUTPUT: --- -fail_compilation/retscope.d(23): Error: scope variable `p` may not be returned -fail_compilation/retscope.d(33): Error: returning `b ? nested1(& i) : nested2(& j)` escapes a reference to local variable `j` -fail_compilation/retscope.d(46): Error: scope variable `p` assigned to non-scope `q` -fail_compilation/retscope.d(48): Error: address of variable `i` assigned to `q` with longer lifetime -fail_compilation/retscope.d(49): Error: variadic variable `a` assigned to non-scope `b` -fail_compilation/retscope.d(50): Error: reference to stack allocated value returned by `(*fp2)()` assigned to non-scope `q` +fail_compilation/retscope.d(22): Error: scope variable `p` may not be returned +fail_compilation/retscope.d(32): Error: returning `b ? nested1(& i) : nested2(& j)` escapes a reference to local variable `j` +fail_compilation/retscope.d(45): Error: scope variable `p` assigned to non-scope `q` +fail_compilation/retscope.d(47): Error: address of variable `i` assigned to `q` with longer lifetime +fail_compilation/retscope.d(48): Error: scope variable `a` assigned to non-scope `b` +fail_compilation/retscope.d(49): Error: address of struct temporary returned by `(*fp2)()` assigned to longer lived variable `q` --- */ @@ -55,8 +54,8 @@ void test2(scope int* p, int[] a ...) @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(76): Error: function retscope.HTTP.Impl.onReceive is @nogc yet allocates closures with the GC -fail_compilation/retscope.d(78): retscope.HTTP.Impl.onReceive.__lambda1 closes over variable this at fail_compilation/retscope.d(76) +fail_compilation/retscope.d(75): Error: function `retscope.HTTP.Impl.onReceive` is `@nogc` yet allocates closures with the GC +fail_compilation/retscope.d(77): retscope.HTTP.Impl.onReceive.__lambda1 closes over variable this at fail_compilation/retscope.d(75) --- */ @@ -86,7 +85,7 @@ struct HTTP /* TEST_OUTPUT: --- -fail_compilation/retscope.d(97): Error: reference to local variable `sa` assigned to non-scope parameter `a` calling retscope.bar8 +fail_compilation/retscope.d(96): Error: reference to local variable `sa` assigned to non-scope parameter `a` calling retscope.bar8 --- */ // https://issues.dlang.org/show_bug.cgi?id=8838 @@ -108,7 +107,7 @@ int[] bar8(int[] a) @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(124): Error: returning `foo9(cast(char[])tmp)` escapes a reference to local variable `tmp` +fail_compilation/retscope.d(123): Error: returning `foo9(cast(char[])tmp)` escapes a reference to local variable `tmp` --- */ @@ -129,7 +128,7 @@ char[] bar9() @safe /* // // -//fail_compilation/retscope.d(143): To enforce @safe compiler allocates a closure unless the opApply() uses 'scope' +//fail_compilation/retscope.d(143): To enforce `@safe`, the compiler allocates a closure unless `opApply()` uses `scope` // */ @@ -150,7 +149,7 @@ S10* test10() /* TEST_OUTPUT: --- -fail_compilation/retscope.d(159): Error: scope variable `this` may not be returned +fail_compilation/retscope.d(158): Error: scope variable `this` may not be returned --- */ @@ -165,7 +164,7 @@ class C11 /* TEST_OUTPUT: --- -fail_compilation/retscope.d(178): Error: address of variable `i` assigned to `p` with longer lifetime +fail_compilation/retscope.d(177): Error: address of variable `i` assigned to `p` with longer lifetime --- */ @@ -182,7 +181,7 @@ void foo11() @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(198): Error: scope variable `e` may not be returned +fail_compilation/retscope.d(197): Error: scope variable `e` may not be returned --- */ @@ -202,7 +201,7 @@ void* escapeDg1(scope void* d) @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(213): Error: scope variable `p` assigned to non-scope `e` +fail_compilation/retscope.d(212): Error: scope variable `p` assigned to non-scope `e.e` --- */ struct Escaper3 { void* e; } @@ -219,7 +218,7 @@ void* escape3 (scope void* p) @safe { /* TEST_OUTPUT: --- -fail_compilation/retscope.d(230): Error: scope variable `ptr` may not be returned +fail_compilation/retscope.d(229): Error: scope variable `ptr` may not be returned --- */ @@ -235,10 +234,10 @@ void* funretscope(scope dg_t ptr) @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda1` of type `void* delegate() pure nothrow @nogc return @safe` to `void* delegate() @safe` -fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda1` of type `void* delegate() pure nothrow @nogc return @safe` to `void* delegate() @safe` -fail_compilation/retscope.d(250): Error: cannot implicitly convert expression `__lambda2` of type `void* delegate() pure nothrow @nogc return @safe` to `void* delegate() @safe` -fail_compilation/retscope.d(250): Error: cannot implicitly convert expression `__lambda2` of type `void* delegate() pure nothrow @nogc return @safe` to `void* delegate() @safe` +fail_compilation/retscope.d(248): Error: cannot implicitly convert expression `__lambda2` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() @safe` +fail_compilation/retscope.d(248): Error: cannot implicitly convert expression `__lambda2` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() @safe` +fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda4` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() @safe` +fail_compilation/retscope.d(249): Error: cannot implicitly convert expression `__lambda4` of type `void* delegate() pure nothrow @nogc @safe` to `void* delegate() @safe` --- */ @@ -255,7 +254,7 @@ void escape4() @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(267): Error: cannot take address of scope local p in @safe function escape5 +fail_compilation/retscope.d(266): Error: cannot take address of `scope` local `p` in `@safe` function `escape5` --- */ @@ -272,7 +271,7 @@ void escape5() @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(287): Error: returning `foo6(& b)` escapes a reference to local variable `b` +fail_compilation/retscope.d(286): Error: returning `foo6(& b)` escapes a reference to local variable `b` --- */ @@ -308,7 +307,7 @@ char*[3] escape9(scope char*[] p) @safe { return p[0 .. 3]; } /* TEST_OUTPUT: --- -fail_compilation/retscope.d(320): Error: reference to local variable `i` assigned to non-scope `f` +fail_compilation/retscope.d(319): Error: reference to local variable `i` assigned to non-scope `f` --- */ @@ -332,7 +331,7 @@ int* bar10( scope int** ptr ) @safe /* TEST_OUTPUT: --- -fail_compilation/retscope.d(343): Error: cannot take address of scope local aa in @safe function escape11 +fail_compilation/retscope.d(342): Error: cannot take address of `scope` local `aa` in `@safe` function `escape11` --- */ @@ -455,7 +454,7 @@ fail_compilation/retscope.d(1311): Error: scope variable `u2` assigned to `ek` w /* TEST_OUTPUT: --- -fail_compilation/retscope.d(1405): Error: reference to local variable `buf` assigned to non-scope parameter `unnamed` calling retscope.myprintf +fail_compilation/retscope.d(1405): Error: reference to local variable `buf` assigned to non-scope parameter `__anonymous_param` calling retscope.myprintf --- */ @@ -473,7 +472,7 @@ fail_compilation/retscope.d(1405): Error: reference to local variable `buf` assi /* TEST_OUTPUT: --- -fail_compilation/retscope.d(1509): Error: reference to stack allocated value returned by `(*fp15)()` assigned to non-scope parameter `unnamed` +fail_compilation/retscope.d(1509): Error: reference to stack allocated value returned by `(*fp15)()` assigned to non-scope parameter `__anonymous_param` --- */ @@ -506,9 +505,9 @@ void foo16() @nogc nothrow TEST_OUTPUT: --- fail_compilation/retscope.d(1701): Error: cannot implicitly convert expression `& func` of type `int* function(int* p)` to `int* function(scope int* p)` -fail_compilation/retscope.d(1702): Error: cannot implicitly convert expression `& func` of type `int* function(int* p)` to `int* function(return scope int* p)` +fail_compilation/retscope.d(1702): Error: cannot implicitly convert expression `& func` of type `int* function(int* p)` to `int* function(return int* p)` fail_compilation/retscope.d(1703): Error: cannot implicitly convert expression `& func` of type `int* function(int* p)` to `int* function(return scope int* p)` -fail_compilation/retscope.d(1711): Error: cannot implicitly convert expression `& funcr` of type `int* function(return scope int* p)` to `int* function(scope int* p)` +fail_compilation/retscope.d(1711): Error: cannot implicitly convert expression `& funcr` of type `int* function(return int* p)` to `int* function(scope int* p)` fail_compilation/retscope.d(1716): Error: cannot implicitly convert expression `& funcrs` of type `int* function(return scope int* p)` to `int* function(scope int* p)` --- */ @@ -660,3 +659,31 @@ int test21() foo22(s); } +/********************************************* +TEST_OUTPUT: +--- +fail_compilation/retscope.d(1907): Error: scope variable `x` assigned to `this` with longer lifetime +fail_compilation/retscope.d(1913): Error: scope variable `x` may not be returned +--- +*/ +#line 1900 +struct Constant +{ + int* member; + + int* foo(scope Repeat!(int*) grid) @safe + { + foreach(ref x; grid) + member = x; + + foreach(ref x; grid) + x = member; + + foreach(ref x; grid) + return x; + + return null; + } + + alias Repeat(T...) = T; +} |