diff options
Diffstat (limited to 'gcc/testsuite/gdc.test/fail_compilation/test21912.d')
-rw-r--r-- | gcc/testsuite/gdc.test/fail_compilation/test21912.d | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21912.d b/gcc/testsuite/gdc.test/fail_compilation/test21912.d new file mode 100644 index 00000000000..8dde98a62b4 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/test21912.d @@ -0,0 +1,54 @@ +/* +PERMUTE_ARGS: -preview=dip1000 +TEST_OUTPUT +--- +fail_compilation/test21912.d(24): Error: function `test21912.escapeParam` is `@nogc` yet allocates closures with the GC +fail_compilation/test21912.d(26): test21912.escapeParam.__lambda2 closes over variable i at fail_compilation/test21912.d(24) +fail_compilation/test21912.d(29): Error: function `test21912.escapeAssign` is `@nogc` yet allocates closures with the GC +fail_compilation/test21912.d(31): test21912.escapeAssign.__lambda3 closes over variable i at fail_compilation/test21912.d(29) +fail_compilation/test21912.d(40): Error: function `test21912.escapeAssignRef` is `@nogc` yet allocates closures with the GC +fail_compilation/test21912.d(42): test21912.escapeAssignRef.__lambda3 closes over variable i at fail_compilation/test21912.d(40) +fail_compilation/test21912.d(51): Error: function `test21912.escapeParamInferred` is `@nogc` yet allocates closures with the GC +fail_compilation/test21912.d(53): test21912.escapeParamInferred.__lambda2 closes over variable i at fail_compilation/test21912.d(51) +--- +*/ +@nogc: + +alias Dg = @nogc int delegate(); + +Dg identity(return scope Dg dg) +{ + return dg; +} + +Dg escapeParam(int i) +{ + return identity(() => i); +} + +Dg escapeAssign(int i, return scope Dg dg) +{ + dg = () => i; + return dg; +} + +ref Dg identityR(ref return scope Dg dg) +{ + return dg; +} + +ref Dg escapeAssignRef(int i, ref return scope Dg dg) +{ + dg = () => i; + return dg; +} + +auto identityInferred(Dg dg) +{ + return dg; +} + +Dg escapeParamInferred(int i) +{ + return identityInferred(() => i); +} |