<div class="gmail_quote">On Mon, Feb 27, 2012 at 2:53 PM, Sebastian Redl <span dir="ltr"><<a href="mailto:sebastian.redl@getdesigned.at">sebastian.redl@getdesigned.at</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div class="im"><div><blockquote type="cite"><p>> +  a = { 1 } = b;</p><p>This is supposed to be ill-formed. How do we handle scalar compound assignments of braced-init-lists? My reading is that such assignments are also ill formed.</p>
</blockquote></div></div>So this actually turns out to be a problem with the way you implemented the parser. The parser just returns after parsing the braced list, but the function that called it (ParseExpression) doesn't know that the expression MUST end and happily calls ParseRHSOfBinaryOp again (with Prec::Comma). Thus, we parse the above as<div>
(a = { 1 }) = b;</div><div>which, while weird, is perfectly valid.</div></div></blockquote><div><br></div><div>Thanks for digging into that! Fixed in r151794.</div><div> </div>On Mon, Feb 27, 2012 at 2:04 PM, Sebastian Redl <span dir="ltr"><<a href="mailto:sebastian.redl@getdesigned.at">sebastian.redl@getdesigned.at</a>></span> wrote:<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="word-wrap:break-word">Compound assignment with a braced-init-list on the RHS is valid.</div></blockquote><div> </div></div>For overloaded operators, sure, but not for scalars. The built-in meaning of compound assignment in [expr.ass]p7 says:<div>
<br></div><div><div>"The behavior of an expression of the form E1 op = E2 is equivalent to E1 = E1 op E2 except that E1 is evaluated only once."</div></div><div><br></div><div>Since "E1 = E1 op { x }" is ill-formed, "E1 op= { x }" is ill-formed too. Also note that [expr.ass]p9 does not assign any meaning to compound assignment from an initializer list. g++ produces a rather charming diagnostic:</div>
<div><br></div><div><div><stdin>:1:39: error: invalid operands of types ‘int’ and ‘<brace-enclosed initializer list>’ to binary ‘operator+’</div><div><stdin>:1:39: error:   in evaluation of ‘operator+=(int, <brace-enclosed initializer list>)’</div>
</div><div><br></div><div>- Richard</div>