-
-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Issue 3672 - Read-modify-write operations should not be allowed f…
…or shared variables.
- Loading branch information
1 parent
58445fb
commit 7535f3d
Showing
4 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// PERMUTE_ARGS: | ||
// REQUIRED_ARGS: -de | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/diag3672.d(38): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(x, 1) instead. | ||
fail_compilation/diag3672.d(39): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(x, 1) instead. | ||
fail_compilation/diag3672.d(40): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"-="(x, 1) instead. | ||
fail_compilation/diag3672.d(41): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"-="(x, 1) instead. | ||
fail_compilation/diag3672.d(42): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(x, 1) instead. | ||
fail_compilation/diag3672.d(43): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(x, 2) instead. | ||
fail_compilation/diag3672.d(44): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"-="(x, 3) instead. | ||
fail_compilation/diag3672.d(45): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"|="(x, y) instead. | ||
fail_compilation/diag3672.d(46): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"*="(x, y) instead. | ||
fail_compilation/diag3672.d(47): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"/="(x, y) instead. | ||
fail_compilation/diag3672.d(48): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"%="(x, y) instead. | ||
fail_compilation/diag3672.d(49): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"&="(x, y) instead. | ||
fail_compilation/diag3672.d(50): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"^="(x, y) instead. | ||
fail_compilation/diag3672.d(51): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"<<="(x, y) instead. | ||
fail_compilation/diag3672.d(52): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!">>="(x, y) instead. | ||
fail_compilation/diag3672.d(53): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!">>>="(x, y) instead. | ||
fail_compilation/diag3672.d(54): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"^^="(x, y) instead. | ||
fail_compilation/diag3672.d(55): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(ptr, 1) instead. | ||
fail_compilation/diag3672.d(56): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(ptr, 1) instead. | ||
fail_compilation/diag3672.d(57): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"-="(ptr, 1) instead. | ||
fail_compilation/diag3672.d(58): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"-="(ptr, 1) instead. | ||
--- | ||
*/ | ||
shared int x; | ||
shared int y; | ||
shared int* ptr; | ||
shared static this() { ptr = new int; } // silence null-dereference errors | ||
class NS { shared int x; } | ||
shared class S { int sx; } | ||
|
||
void main() | ||
{ | ||
++x; | ||
x++; | ||
--x; | ||
x--; | ||
x += 1; | ||
x += 2; | ||
x -= 3; | ||
x |= y; | ||
x *= y; | ||
x /= y; | ||
x %= y; | ||
x &= y; | ||
x ^= y; | ||
x <<= y; | ||
x >>= y; | ||
x >>>= y; | ||
x ^^= y; | ||
++ptr; | ||
ptr++; | ||
--ptr; | ||
ptr--; | ||
NS ns = new NS; | ||
ns.x++; | ||
S s = new S; | ||
s.sx++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/fail3672.d(28): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(*p, 1) instead. | ||
fail_compilation/fail3672.d(32): Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(*sfp, 1) instead. | ||
fail_compilation/fail3672.d(32): Error: '*sfp += 1' is not a scalar, it is a shared(SF) | ||
fail_compilation/fail3672.d(32): Error: incompatible types for ((*sfp) += (1)): 'shared(SF)' and 'int' | ||
--- | ||
*/ | ||
struct SF // should fail | ||
{ | ||
void opOpAssign(string op, T)(T rhs) | ||
{ | ||
} | ||
} | ||
|
||
struct SK // ok | ||
{ | ||
void opOpAssign(string op, T)(T rhs) shared | ||
{ | ||
} | ||
} | ||
|
||
void main() | ||
{ | ||
shared int x; | ||
auto p = &x; | ||
*p += 1; // fail | ||
|
||
shared SF sf; | ||
auto sfp = &sf; | ||
*sfp += 1; // fail | ||
|
||
shared SK sk; | ||
auto skp = &sk; | ||
sk += 1; // ok | ||
*skp += 1; // ok | ||
} |