Skip to content

Commit

Permalink
Issue 18743 - ConditionalExpression with AssignExpression requires pa…
Browse files Browse the repository at this point in the history
…rens
  • Loading branch information
ntrel committed Jun 6, 2018
1 parent 6afeb37 commit fe4dd55
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/expression.dd
Expand Up @@ -165,6 +165,28 @@ $(GNAME ConditionalExpression):
the result type of the conditional expression.
)

$(P $(B Note:)
When a conditional expression is the left operand of
an $(RELATIVE_LINK2 assign_expressions, assign expression), they would be
parsed as an assignment to $(I the result) of the conditional. This
has now been deprecated. To preserve the existing behaviour, add
parentheses for the conditional without including the assignment:
)
---
bool test;
int a, b, c;
...
test ? a = b : c = 2; // Deprecated
(test ? a = b : c) = 2; // Equivalent
---

$(P This makes the intent clearer, because the first statement can
easily be misread as the following code:
)
---
test ? a = b : (c = 2);
---

$(H2 $(LNAME2 oror_expressions, OrOr Expressions))

$(GRAMMAR
Expand Down

0 comments on commit fe4dd55

Please sign in to comment.