1 /* REQUIRED_ARGS: -preview=nosharedaccess
4 fail_compilation/shared.d(1010): Error: direct access to shared `j` is not allowed, see `core.atomic`
5 fail_compilation/shared.d(1011): Error: direct access to shared `j` is not allowed, see `core.atomic`
6 fail_compilation/shared.d(1012): Error: direct access to shared `*p` is not allowed, see `core.atomic`
7 fail_compilation/shared.d(1013): Error: direct access to shared `a[0]` is not allowed, see `core.atomic`
8 fail_compilation/shared.d(1014): Error: direct access to shared `s.si` is not allowed, see `core.atomic`
9 fail_compilation/shared.d(1015): Error: direct access to shared `t.i` is not allowed, see `core.atomic`
21 int test1(shared int j
, shared(int)* p
, shared(int)[] a
, ref S s
, ref shared S t
)
32 /**************************************/
34 void byref(ref shared int);
35 void byptr(shared(int)*);
45 /**************************************/
50 fail_compilation/shared.d(2008): Error: direct access to shared `i` is not allowed, see `core.atomic`
51 fail_compilation/shared.d(2009): Error: direct access to shared `j` is not allowed, see `core.atomic`
52 fail_compilation/shared.d(2010): Error: direct access to shared `k` is not allowed, see `core.atomic`
62 void test3(shared int k
)
70 /**************************************/
72 void test4() // no errors for initialization
81 fail_compilation/shared.d(2105): Error: direct access to shared `*pi` is not allowed, see `core.atomic`
82 fail_compilation/shared.d(2112): Error: direct access to shared `**pi` is not allowed, see `core.atomic`
83 fail_compilation/shared.d(2136): Error: direct access to shared `*c` is not allowed, see `core.atomic`
84 fail_compilation/shared.d(2142): Error: direct access to shared `*c` is not allowed, see `core.atomic`
85 fail_compilation/shared.d(2148): Error: direct access to shared `*c` is not allowed, see `core.atomic`
86 fail_compilation/shared.d(2154): Error: direct access to shared `*c.c1` is not allowed, see `core.atomic`
87 fail_compilation/shared.d(2160): Error: direct access to shared `*c.c1.c1` is not allowed, see `core.atomic`
88 fail_compilation/shared.d(2181): Error: direct access to shared `k` is not allowed, see `core.atomic`
89 fail_compilation/shared.d(2187): Error: direct access to shared `k.k2.k1` is not allowed, see `core.atomic`
90 fail_compilation/shared.d(2194): Error: direct access to shared `(new shared(K2)).k1` is not allowed, see `core.atomic`
91 fail_compilation/shared.d(2202): Error: direct access to shared `c` is not allowed, see `core.atomic`
92 fail_compilation/shared.d(2206): Error: function `shared.test_inference_2` function returns `shared` but cannot be inferred `ref`
93 fail_compilation/shared.d(2208): Error: returning `c` escapes a reference to parameter `c`
94 fail_compilation/shared.d(2214): Error: function `shared.test_inference_3` function returns `shared` but cannot be inferred `ref`
95 fail_compilation/shared.d(2216): return value `getSharedObject()` is not an lvalue
96 fail_compilation/shared.d(2222): Error: direct access to shared `a` is not allowed, see `core.atomic`
97 fail_compilation/shared.d(2220): Error: function `shared.test_inference_4` function returns `shared` but cannot be inferred `ref`
98 fail_compilation/shared.d(2222): cannot implicitly convert `a` of type `shared(const(Object))` to `object.Object`
99 fail_compilation/shared.d(2222): Error: cannot implicitly convert expression `a` of type `shared(const(Object))` to `object.Object`
104 // Derived from https://issues.dlang.org/show_bug.cgi?id=20908
105 ref shared(int) test20908()
108 // Single indirection, but the pointer is `shared`
112 ref shared(int) test20908_2()
115 // Double indirection, external pointer is not `shared`
119 // DotVarExp tests: See matching tests in `compilable/shared.d`
137 // Reading a shared pointer: not okay
138 ref shared(int) test_dotvarexp_1(return shared C1
* c
)
143 // Ditto, but explicitly dereferenced
144 ref shared(int) test_dotvarexp_2(return shared C1
* c
)
149 // Even taking the address (which offset the pointers) requires a load
150 shared(int)* test_dotvarexp_3(return shared C1
* c
)
155 // First level DotVarExp dereferencing
156 ref shared(int) test_dotvarexp_4(return shared ref C2 c
)
161 // Second level DotVarExp dereferencing
162 ref shared(int) test_dotvarexp_5(return shared ref C3 c
)
164 return c
.c1
.c1
.value
;
182 // A class is a pointer under the hood, and `shared` applies to the pointer
183 ref shared(int) test_dotvarexp_6(return shared K1 k
)
188 // Using `k.ke.k1` would be okay, but not `value`
189 ref shared(int) test_dotvarexp_7(return ref K3 k
)
191 return k
.k2
.k1
.value
;
194 // The returned value is `shared` so we shouldn't be able to access it
195 // The pointer could already be shared, e.g. by the ctor
196 ref shared(K1
) test_newexp_1()
198 return new shared(K2
)().k1
;
203 // Fails because no `ref`
204 auto test_inference_1(return shared ref C3 c
)
209 // Fails because no `return` => Escapes
210 auto ref test_inference_2(shared C3 c
)
215 shared(Object
) getSharedObject() { assert(0); }
217 // Fails because rvalue
218 auto ref test_inference_3()
220 return getSharedObject();
223 // Fails because `const` conversion
224 auto ref Object
test_inference_4(const return shared ref Object a
)