Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test20734.d

raw
1 /*
2 REQUIRED_ARGS: -betterC -preview=dip1000
3 */
4
5 __gshared int numDtor;
6
7 struct S
8 {
9 int a;
10 ~this() nothrow @nogc @trusted { ++numDtor; }
11 }
12
13 void takeScopeSlice(const scope S[] slice) nothrow @nogc @safe {}
14
15 extern(C) int main() nothrow @nogc @safe
16 {
17 takeScopeSlice([ S(1), S(2) ]); // @nogc => no GC allocation
18 (() @trusted { assert(numDtor == 2); })(); // stack-allocated array literal properly destructed
19 assert23100([]);
20
21 // https://issues.dlang.org/show_bug.cgi?id=22306
22 // scope array variable should be stack allocated
23 scope int[] sa = [10, 20];
24 assert(sa[0] == 10);
25 assert(sa[1] == 20);
26 assert(sa.length == 2);
27
28 return 0;
29 }
30
31 // https://issues.dlang.org/show_bug.cgi?id=23098
32 void f23098(scope inout(int)[] d) @safe {}
33
34 void test23098() @safe
35 {
36 f23098([10, 20]);
37 }
38
39 // https://issues.dlang.org/show_bug.cgi?id=23100
40 void assert23100(scope int[] d) @safe nothrow @nogc
41 {
42 assert(!d);
43 }