]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/fail_compilation/fail3672.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / fail3672.d
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail3672.d(28): Error: read-modify-write operations are not allowed for `shared` variables
5 fail_compilation/fail3672.d(28): Use `core.atomic.atomicOp!"+="(*p, 1)` instead
6 fail_compilation/fail3672.d(32): Error: none of the `opOpAssign` overloads of `SF` are callable for `*sfp` of type `shared(SF)`
7 ---
8 */
9
10 struct SF // should fail
11 {
12 void opOpAssign(string op, T)(T rhs)
13 {
14 }
15 }
16
17 struct SK // ok
18 {
19 void opOpAssign(string op, T)(T rhs) shared
20 {
21 }
22 }
23
24 void main()
25 {
26 shared int x;
27 auto p = &x;
28 *p += 1; // fail
29
30 shared SF sf;
31 auto sfp = &sf;
32 *sfp += 1; // fail
33
34 shared SK sk;
35 auto skp = &sk;
36 sk += 1; // ok
37 *skp += 1; // ok
38 }