Skip to content

Commit 18f70c4

Browse files
authored
Merge pull request #2366 from ntrel/cond-assign
Issue 18743 - ConditionalExpression with AssignExpression requires parens
2 parents f0c63a5 + 3685d36 commit 18f70c4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

spec/expression.dd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ $(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),
171+
parentheses are required for disambiguation:
172+
)
173+
---
174+
bool test;
175+
int a, b, c;
176+
...
177+
test ? a = b : c = 2; // Deprecated
178+
(test ? a = b : c) = 2; // Equivalent
179+
---
180+
181+
$(P This makes the intent clearer, because the first statement can
182+
easily be misread as the following code:
183+
)
184+
---
185+
test ? a = b : (c = 2);
186+
---
187+
168188
$(H2 $(LNAME2 oror_expressions, OrOr Expressions))
169189

170190
$(GRAMMAR

0 commit comments

Comments
 (0)