Debian Codegraph @

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

raw
1 /*
2 REQUIRED_ARGS: -preview=systemVariables
3 TEST_OUTPUT:
4 ---
5 fail_compilation/systemvariables.d(39): Error: access `@system` variable `gInt` is not allowed in a `@safe` function
6 fail_compilation/systemvariables.d(29): `gInt` is declared here
7 fail_compilation/systemvariables.d(40): Error: access `@system` variable `gInt` is not allowed in a `@safe` function
8 fail_compilation/systemvariables.d(29): `gInt` is declared here
9 fail_compilation/systemvariables.d(41): Error: access `@system` variable `gArr` is not allowed in a `@safe` function
10 fail_compilation/systemvariables.d(31): `gArr` is declared here
11 fail_compilation/systemvariables.d(42): Error: access `@system` variable `gArr` is not allowed in a `@safe` function
12 fail_compilation/systemvariables.d(31): `gArr` is declared here
13 fail_compilation/systemvariables.d(43): Error: access `@system` variable `gInt` is not allowed in a `@safe` function
14 fail_compilation/systemvariables.d(29): `gInt` is declared here
15 fail_compilation/systemvariables.d(46): Error: access `@system` variable `lSys` is not allowed in a `@safe` function
16 fail_compilation/systemvariables.d(45): `lSys` is declared here
17 fail_compilation/systemvariables.d(47): Error: access `@system` variable `lSys` is not allowed in a `@safe` function
18 fail_compilation/systemvariables.d(45): `lSys` is declared here
19 fail_compilation/systemvariables.d(48): Error: access `@system` variable `lSys` is not allowed in a `@safe` function
20 fail_compilation/systemvariables.d(45): `lSys` is declared here
21 fail_compilation/systemvariables.d(50): Error: access `@system` variable `eInt` is not allowed in a `@safe` function
22 fail_compilation/systemvariables.d(30): `eInt` is declared here
23 ---
24 */
25
26 // http://dlang.org/dips/1035
27
28
29 @system int gInt;
30 @system enum int eInt = 3;
31 @system { int[] gArr; }
32 alias aliasToSys = gInt;
33
34 void increment(ref int x) @safe { x++; }
35 void incrementP(int* x) @safe { (*x)++; }
36
37 void basic() @safe
38 {
39 gInt = 0; // error
40 gInt++; // error
41 gArr ~= 30; // error
42 const c = gArr[0]; // error
43 aliasToSys++; // error
44
45 @system int lSys = 0;
46 lSys = 0; // error
47 increment(lSys); // error
48 incrementP(&lSys); // error
49
50 int a = eInt; // error
51 int b = typeof(eInt).max; // allowed
52
53 void f() @trusted
54 {
55 lSys = 0; // allowed
56 }
57 }