From fe4dd55a8a1f486d4db6f93b5fcc72a009367f36 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 12 May 2018 14:43:53 +0100 Subject: [PATCH] Issue 18743 - ConditionalExpression with AssignExpression requires parens --- spec/expression.dd | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/expression.dd b/spec/expression.dd index 70a2447ec1..83e5d1b966 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -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