[cfe-commits] r151551 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/expr/expr.ass/p9-cxx11.cpp

Richard Smith richard at metafoo.co.uk
Wed Feb 29 19:05:29 PST 2012


On Mon, Feb 27, 2012 at 2:53 PM, Sebastian Redl <
sebastian.redl at getdesigned.at> wrote:

> > +  a = { 1 } = b;
>
> 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.
>
> 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
> (a = { 1 }) = b;
> which, while weird, is perfectly valid.
>

Thanks for digging into that! Fixed in r151794.

On Mon, Feb 27, 2012 at 2:04 PM, Sebastian Redl <
sebastian.redl at getdesigned.at> wrote:
>
> Compound assignment with a braced-init-list on the RHS is valid.
>

For overloaded operators, sure, but not for scalars. The built-in meaning
of compound assignment in [expr.ass]p7 says:

"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."

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:

<stdin>:1:39: error: invalid operands of types ‘int’ and ‘<brace-enclosed
initializer list>’ to binary ‘operator+’
<stdin>:1:39: error:   in evaluation of ‘operator+=(int, <brace-enclosed
initializer list>)’

- Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120229/02f653fe/attachment.html>


More information about the cfe-commits mailing list