Skip to content

Commit fe4dd55

Browse files
committed
Issue 18743 - ConditionalExpression with AssignExpression requires parens
1 parent 6afeb37 commit fe4dd55

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec/expression.dd

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,28 @@ $(GNAME ConditionalExpression):
165165
the result type of the conditional expression.
166166
)
167167

168+
$(P $(B Note:)
169+
When a conditional expression is the left operand of
170+
an $(RELATIVE_LINK2 assign_expressions, assign expression), they would be
171+
parsed as an assignment to $(I the result) of the conditional. This
172+
has now been deprecated. To preserve the existing behaviour, add
173+
parentheses for the conditional without including the assignment:
174+
)
175+
---
176+
bool test;
177+
int a, b, c;
178+
...
179+
test ? a = b : c = 2; // Deprecated
180+
(test ? a = b : c) = 2; // Equivalent
181+
---
182+
183+
$(P This makes the intent clearer, because the first statement can
184+
easily be misread as the following code:
185+
)
186+
---
187+
test ? a = b : (c = 2);
188+
---
189+
168190
$(H2 $(LNAME2 oror_expressions, OrOr Expressions))
169191

170192
$(GRAMMAR

0 commit comments

Comments
 (0)