| 1 |
// https://issues.dlang.org/show_bug.cgi?id=22626 |
| 2 |
// REQUIRED_ARGS: -preview=nosharedaccess |
| 3 |
|
| 4 |
shared int k; |
| 5 |
|
| 6 |
class Oops |
| 7 |
{ |
| 8 |
shared int a; |
| 9 |
shared int* pa; |
| 10 |
synchronized void oops() |
| 11 |
{ |
| 12 |
// this should compile since the function is synchronized |
| 13 |
// and `a` is accessed through `this`. |
| 14 |
a = 2; |
| 15 |
|
| 16 |
// this shouldn't compile because synchronized guards |
| 17 |
// only accesses to the first level of dereferencing |
| 18 |
static assert (!__traits(compiles, *pa = 2)); |
| 19 |
|
| 20 |
// this shouldn't compile `k` is a field of class `Oops` |
| 21 |
static assert (!__traits(compiles, k = 2)); |
| 22 |
} |
| 23 |
|
| 24 |
// https://issues.dlang.org/show_bug.cgi?id=24705 |
| 25 |
synchronized void foo(int n) |
| 26 |
{ |
| 27 |
// Error: direct access to shared `n` is not allowed, see `core.atomic` |
| 28 |
int a = n; |
| 29 |
} |
| 30 |
} |