On Saturday, April 07, 2018 14:28:05 kdevel via Digitalmars-d wrote: > On Saturday, 7 April 2018 at 09:56:43 UTC, Jonathan M Davis wrote: > >> true?stt="AA":stt="BB"; <<<<-----///Out:BB > > [...] > > > Assignment takes precendence over the ternary operator. > > That's not true. Not in D and not in C/C++ > https://wiki.dlang.org/Operator_precedence > http://en.cppreference.com/w/c/language/operator_precedence#cite_note-2 > > > So, no, I don't think that it is. Putting parens around the > > assignment expressions makes it print AA. > > It should not matter if there are parens around the assignment. > > > As it stands, it evaluates both assignment expressions before > > evaluating the ternary operator. > > That is not true in C/C++, let me quote from a C standard > (draft), § 6.1.5 conditional operator: > > [this is about <first op> ? <second op> : <third op>] > > "Semantics > > The first operand is evaluated; there is a sequence point between > its evaluation and the evaluation of the second or third operand > (whichever is evaluated). The second operand is evaluated only if > the first compares unequal to 0; the third operand is evaluated > only if the first compares equal to 0; the result is the value of > the second or third operand (whichever is evaluated), converted > to the type described below.110)" > > According to > > https://dlang.org/spec/expression.html#conditional_expressions > > the same shall be valid for D. Hence when > > true ? s = A : s = B; > > or > > true ? (s = A) : (s = B); > > does not yield A for s it's a bug.
You're right. It's what I get for responding too early in the morning. - Jonathan M Davis