[Issue 18743] ConditionalExpression and AssignExpression should require parentheses
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Apr 8 16:57:16 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18743
Patrick Schluter <Patrick.Schluter at ec.europa.eu> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Patrick.Schluter at ec.europa.
| |eu
--- Comment #3 from Patrick Schluter <Patrick.Schluter at ec.europa.eu> ---
(In reply to David Nadlinger from comment #1)
> This isn't a bug.
>
> In D, ?: has higher precedence than =, so
>
> true ? stt = "AA" : stt = "BB"
>
> means
>
> (true ? (stt = "AA") : stt) = "BB",
>
> in line with C and other languages, but notably not C++.
>
> The operator precedence should be documented somewhere, though; while there
> is a table in TDPL (p. 61 ff.) and on the Wiki
> (https://wiki.dlang.org/Operator_precedence), I can't seem to find it on
> dlang.org/spec.
>
> ---
>
> Changing this to an enhancement request, as we should really consider
> requiring explicit parenthesization for this sort of error-prone code,
> similar to how we disallow assignment expressions in if statements.
How on earth can
(true ? (stt = "AA") : stt) = "BB"
compile?
(stt = "AA") is not a lvalue or is it?
It looks like D compiles
int a, b;
(a=1)=2;
without problem. That's what surprizing here (at least for a C guy), not the
precedence of the ternary.
--
More information about the Digitalmars-d-bugs
mailing list