Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/attributediagnostic_nogc.d

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/attributediagnostic_nogc.d(21): Error: `@nogc` function `attributediagnostic_nogc.layer2` cannot call non-@nogc function `attributediagnostic_nogc.layer1`
5 fail_compilation/attributediagnostic_nogc.d(22): which calls `layer0`
6 fail_compilation/attributediagnostic_nogc.d(23): which calls `gc`
7 fail_compilation/attributediagnostic_nogc.d(27): and executing an `asm` statement without `@nogc` annotation makes it fail to infer `@nogc`
8 fail_compilation/attributediagnostic_nogc.d(43): Error: `@nogc` function `D main` cannot call non-@nogc function `attributediagnostic_nogc.gc1`
9 fail_compilation/attributediagnostic_nogc.d(32): and allocating with `new` makes it fail to infer `@nogc`
10 fail_compilation/attributediagnostic_nogc.d(44): Error: `@nogc` function `D main` cannot call non-@nogc function `attributediagnostic_nogc.gc2`
11 fail_compilation/attributediagnostic_nogc.d(38): and calling non-@nogc `fgc` makes it fail to infer `@nogc`
12 fail_compilation/attributediagnostic_nogc.d(45): Error: `@nogc` function `D main` cannot call non-@nogc function `attributediagnostic_nogc.gcClosure`
13 fail_compilation/attributediagnostic_nogc.d(48): and allocating a closure for `gcClosure()` makes it fail to infer `@nogc`
14 ---
15 */
16 #line 18
17 // Issue 17374 - Improve inferred attribute error message
18 // https://issues.dlang.org/show_bug.cgi?id=17374
19
20 auto layer2() @nogc { layer1(); }
21 auto layer1() { layer0(); }
22 auto layer0() { gc(); }
23
24 auto gc()
25 {
26 asm {}
27 }
28
29 auto gc1()
30 {
31 int* x = new int;
32 }
33
34 auto fgc = function void() {new int[10];};
35 auto gc2()
36 {
37 fgc();
38 }
39
40 void main() @nogc
41 {
42 gc1();
43 gc2();
44 gcClosure();
45 }
46
47 auto gcClosure()
48 {
49 int x;
50 int bar() { return x; }
51 return &bar;
52 }