<br><br><div class="gmail_quote">On Tue, Oct 26, 2010 at 4:16 PM, Frits van Bommel <span dir="ltr"><<a href="mailto:fvbommel@gmail.com">fvbommel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Tue, Oct 26, 2010 at 4:53 AM, Zhongxing Xu <<a href="mailto:xuzhongxing@gmail.com">xuzhongxing@gmail.com</a>> wrote:<br>
> Only statements containing control flow could cause 'Block' to be NULL, e.g.<br>
> DoStmt, WhileStmt, CastStmt. They do occur in the RHS of assignments, but<br>
> they do not occur in the LHS of assignments. So I think it's safe here. Or I<br>
> could miss something?<br>
<br>
</div>The following code is accepted by both gcc and clang in c++ mode, even<br>
if -pedantic and/or -std=c++98 is passed:<br>
=====<br>
int* iftrue();<br>
int* iffalse();<br>
<br>
void conditional_assign (int cond, int val) {<br>
    (cond ? *iftrue() : *iffalse()) = val;<br>
}<br>
=====<br>
<br>
Neither will compile it in C mode as-is, but both are fine with it if<br>
I put move the dereference to before the opening bracket. (Again, even<br>
with -pedantic and/or (-std=c89 or -std=c99)<br>
Apparently C doesn't preserve the lvalue-ness of the conditional<br>
operator's operands, but C++ does. Not really surprising given that<br>
C++ has an int& type but C doesn't; in C++ their types are int& while<br>
in C they're probably plain old ints.<br>
<br>
Anyway, this is an example of code clang (like gcc) compiles without<br>
complaining that has control flow in the LHS of an assignment<br>
operator.<br></blockquote><div><br>conditional operator does not terminate the current 'Block'. So this does no harm.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br>
I didn't check whether statement expressions are allowed in the LHS,<br>
but that could be another case.<br></blockquote><div><br>StmtExpr cannot produce an lvalue, so they cannot appear in the LHS of an assignment. <br></div></div><br>