Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/diag10862.d

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/diag10862.d(40): Error: assignment cannot be used as a condition, perhaps `==` was meant?
5 fail_compilation/diag10862.d(41): Error: assignment cannot be used as a condition, perhaps `==` was meant?
6 fail_compilation/diag10862.d(42): Error: assignment cannot be used as a condition, perhaps `==` was meant?
7 fail_compilation/diag10862.d(43): Error: assignment cannot be used as a condition, perhaps `==` was meant?
8 fail_compilation/diag10862.d(44): Error: assignment cannot be used as a condition, perhaps `==` was meant?
9 fail_compilation/diag10862.d(46): Error: assignment cannot be used as a condition, perhaps `==` was meant?
10 fail_compilation/diag10862.d(47): Error: assignment cannot be used as a condition, perhaps `==` was meant?
11 fail_compilation/diag10862.d(48): Error: assignment cannot be used as a condition, perhaps `==` was meant?
12 fail_compilation/diag10862.d(49): Error: assignment cannot be used as a condition, perhaps `==` was meant?
13 fail_compilation/diag10862.d(51): Error: assignment cannot be used as a condition, perhaps `==` was meant?
14 fail_compilation/diag10862.d(52): Error: assignment cannot be used as a condition, perhaps `==` was meant?
15 fail_compilation/diag10862.d(53): Error: assignment cannot be used as a condition, perhaps `==` was meant?
16 fail_compilation/diag10862.d(54): Error: assignment cannot be used as a condition, perhaps `==` was meant?
17 fail_compilation/diag10862.d(56): Error: assignment cannot be used as a condition, perhaps `==` was meant?
18 fail_compilation/diag10862.d(57): Error: assignment cannot be used as a condition, perhaps `==` was meant?
19 fail_compilation/diag10862.d(58): Error: assignment cannot be used as a condition, perhaps `==` was meant?
20 fail_compilation/diag10862.d(59): Error: assignment cannot be used as a condition, perhaps `==` was meant?
21 fail_compilation/diag10862.d(61): Error: undefined identifier `semanticError`
22 fail_compilation/diag10862.d(71): Error: assignment cannot be used as a condition, perhaps `==` was meant?
23 fail_compilation/diag10862.d(74): Error: assignment cannot be used as a condition, perhaps `==` was meant?
24 fail_compilation/diag10862.d-mixin-77(77): Error: assignment cannot be used as a condition, perhaps `==` was meant?
25 fail_compilation/diag10862.d-mixin-78(78): Error: assignment cannot be used as a condition, perhaps `==` was meant?
26 fail_compilation/diag10862.d-mixin-79(79): Error: assignment cannot be used as a condition, perhaps `==` was meant?
27 fail_compilation/diag10862.d-mixin-80(80): Error: using the result of a comma expression is not allowed
28 fail_compilation/diag10862.d-mixin-80(80): Error: assignment cannot be used as a condition, perhaps `==` was meant?
29 fail_compilation/diag10862.d-mixin-83(83): Error: cannot modify expression `a + b` because it is not an lvalue
30 fail_compilation/diag10862.d-mixin-84(84): Error: undefined identifier `c`
31 fail_compilation/diag10862.d(86): Error: undefined identifier `semanticError`
32 fail_compilation/diag10862.d(93): Error: cannot modify lazy variable `bar`
33 fail_compilation/diag10862.d(95): Error: template instance `diag10862.test3.foo!int` error instantiating
34 ---
35 */
36 void test1()
37 {
38 int a, b;
39
40 if (a = b) {}
41 if ((a = b) = 0) {}
42 if ((a = b) = (a = b)) {}
43 if (a = 0, b = 0) {} // https://issues.dlang.org/show_bug.cgi?id=15384
44 if (auto x = a = b) {} // this is error, today
45
46 while (a = b) {}
47 while ((a = b) = 0) {}
48 while ((a = b) = (a = b)) {}
49 while (a = 0, b = 0) {} // https://issues.dlang.org/show_bug.cgi?id=15384
50
51 do {} while (a = b);
52 do {} while ((a = b) = 0);
53 do {} while ((a = b) = (a = b));
54 do {} while (a = 0, b = 0); // https://issues.dlang.org/show_bug.cgi?id=15384
55
56 for (; a = b; ) {}
57 for (; (a = b) = 0; ) {}
58 for (; (a = b) = (a = b); ) {}
59 for (; a = 0, b = 0; ) {} // https://issues.dlang.org/show_bug.cgi?id=15384
60
61 semanticError;
62 }
63
64 void test2()
65 {
66 int a, b;
67
68 // (a + b) cannot be an assignment target.
69 // However checkAssignAsCondition specilatively rerites it to EqualExp,
70 // then the pointless error "is not an lvalue" would not happen.
71 if (a + b = a * b) {}
72
73 // The suggestion error masks "undefined identifier" error
74 if (a = undefinedIdentifier) {}
75
76 // If the condition is a mixin expression
77 if (mixin("a = b")) {}
78 if (mixin("(a = b) = 0")) {}
79 if (mixin("(a = b) = (a = b)")) {}
80 if (mixin("a = 0, b = 0")) {}
81 if (auto x = mixin("a = b")) {} // Note: no error
82
83 if (mixin("a + b = a * b")) {} // Note: "a + b is not an lvalue"
84 if (mixin("a = c")) {}
85
86 semanticError;
87 }
88
89 void test3()
90 {
91 void foo(T)(lazy T bar)
92 {
93 bar = 2;
94 }
95 foo(1 + 1);
96 }