d: Merge upstream dmd 568496d5b, druntime 178c44ff, phobos 574bf883b.
[official-gcc.git] / gcc / testsuite / gdc.test / compilable / shared.d
blobbfa84224d792f8d164c1d97a86c202fea2aa92f7
1 /* REQUIRED_ARGS: -preview=nosharedaccess
2 TEST_OUTPUT:
3 ---
4 pure nothrow @nogc ref @safe shared(C1)(return ref shared(C1) c)
5 pure nothrow @nogc ref @safe shared(int)(return ref shared(C3) c)
6 ---
7 */
8 ref shared(int) f(return shared ref int y)
10 return y;
13 // https://issues.dlang.org/show_bug.cgi?id=20908
14 void test20908()
16 // shared locals (or struct members) should be able to be initialised:
17 shared int x;
19 ref shared(int) fun()
21 static shared(int) val;
23 // return by reference
24 return val;
27 ref shared(int) fun2()
29 static shared(int)* val;
31 // transfer pointer to reference
32 return *val;
35 ref shared(int) fun3()
37 static shared(int)*** val;
39 // Multiple indirections
40 return ***val;
44 // Simple tests for `DotVarExp`
45 // A `DotVarExp` is `a.b`. If `a` is a `shared ref`,
46 // it is of type `shared(T)*` (as opposed to `shared(T*)`).
47 // We should allow arbitrarily nested `DotVarExp` as long
48 // as no shared memory is read, as in the case above
49 // (we're just offsetting a pointer).
50 struct C1
52 int value;
55 struct C2
57 C1 c1;
60 struct C3
62 C2 c1;
63 C2 c2;
66 ref shared(int) test_dotvarexp_1(return ref shared C1 c)
68 return c.value;
71 shared(int)* test_dotvarexp_2(return ref shared C1 c)
73 return &c.value;
76 shared(C2)* test_dotvarexp_3(return ref shared C3 c)
78 return &c.c1;
81 shared(C2)* test_dotvarexp_4(return ref shared C3 c)
83 return &c.c2;
86 ref shared(int) test_dotvarexp_5(return shared ref C3 c)
88 return c.c1.c1.value;
91 ref shared(int) test_dotvarexp_5(return ref shared(C3)[] c)
93 return c[0].c1.c1.value;
96 // Test `auto` inference
97 auto ref test_inference_1(return ref shared C1 c)
99 return c;
102 pragma(msg, typeof(test_inference_1));
104 auto ref test_inference_2(return ref shared C3 c)
106 return c.c2.c1.value;
109 pragma(msg, typeof(test_inference_2));
111 // https://issues.dlang.org/show_bug.cgi?id=21793
113 struct Child
115 this(int) shared {}
118 struct Parent
120 shared Child ch;
121 this(int i) shared
123 ch = shared Child(i);