]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/fail_compilation/test15544.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test15544.d
1 /*
2 REQUIRED_ARGS: -dip1000
3 PERMUTE_ARGS:
4 TEST_OUTPUT:
5 ---
6 fail_compilation/test15544.d(21): Error: reference to local `this` assigned to non-scope `_del` in @safe code
7 fail_compilation/test15544.d(23): Error: reference to local `this` assigned to non-scope `_del` in @safe code
8 ---
9 */
10
11 // https://issues.dlang.org/show_bug.cgi?id=15544
12
13 void delegate() @safe _del;
14
15 struct S {
16 int x = 42;
17
18 @safe void test()
19 {
20 void foo() { assert(x == 42); }
21 _del = &foo;
22
23 _del = { assert(x == 42); };
24 }
25 }
26
27 /*
28 TEST_OUTPUT:
29 ---
30 fail_compilation/test15544.d(47): Error: reference to local `y` assigned to non-scope `dg` in @safe code
31 ---
32 */
33
34 int delegate() dg;
35
36 void testClosure1()
37 {
38 int* x;
39 int bar() { return *x; }
40 dg = &bar;
41 }
42
43 @safe void testClosure2()
44 {
45 scope int* y;
46 int bar() { return *y; }
47 dg = &bar; // Error
48 auto dg2 = &bar;
49 }
50
51