<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 18, 2020 at 10:59 AM Billy Araujo <<a href="mailto:billyaraujo@gmail.com">billyaraujo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div>Hi David,</div><div><br></div><div>Actually the situation you present foo(x =5); is interesting because gcc 10 flags this while clang 10 doesn't: </div><div><br></div><div><a href="https://godbolt.org/z/NXUPrU" target="_blank">https://godbolt.org/z/NXUPrU</a><br></div><div><br></div><div><span style="box-sizing:border-box;font-weight:bolder;color:rgb(0,123,253);font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:18.6667px;white-space:pre-wrap;background-color:rgb(245,245,245)"><span style="box-sizing:border-box;color:rgb(170,0,170)">warning: </span></span><span style="color:rgb(0,123,253);font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:18.6667px;white-space:pre-wrap;background-color:rgb(245,245,245)">suggest parentheses around assignment used as truth value</span> </div><div><br></div></div></blockquote><div><br></div><div>Ah, well, missed opportunity for Clang, then! (bug/missing feature, I'd say - though clang-to-clang backwards compatibility might make that hard to roll out in clang at this point, not sure)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div>@Roman. Thanks for the further explanation. That makes sense.</div><div><br></div><div>Regards,</div><div><br></div><div>Billy.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 18, 2020 at 6:49 PM Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com" target="_blank">lebedev.ri@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, May 18, 2020 at 8:44 PM Billy Araujo via cfe-dev<br>
<<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hi David,<br>
><br>
> So I guess this is expected behaviour. Thanks.<br>
><br>
> Regards,<br>
><br>
> Billy.<br>
><br>
><br>
> On Mon, May 18, 2020 at 6:39 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
>><br>
>> GCC doesn't seem to warn on this either. On the basis of the original warning I could see how this case could merit similar handling - but I doubt we'd want to add that handling to the existing flag at this point (due to the number of people over the decades that have used the warning for the behavior it currently provides, not expecting the new/additional behavior for the ternary operator or other bool-testing assignment situations (eg: "void f(bool); f(x = 5);")<br>
>><br>
>> On Mon, May 18, 2020 at 6:53 AM Billy Araujo via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
>>><br>
>>> -Wparentheses<br>
>>><br>
>>> warns for line 3 but not for the ternary expression in line 2.<br>
>>><br>
>>> 1 static void foo(int a, int b, int x) {<br>
>>> 2 x = (x = 10) ? a : b;<br>
>>> 3 if (x = 10) { x = a; } else { x = b; }<br>
>>> 4 }<br>
>>><br>
>>> Is this a bug?<br>
This seems pretty correct to me.<br>
<br>
You can't avoid braces on line 3, so those braces don't count as extra braces<br>
to silence the diagnostic, while the situation on the line 2 is opposite,<br>
no braces are needed there, so the braces count as silencers.<br>
<br>
I.e. if line 2 *would* be diagnosed, i'd say that is a false-positive.<br>
<br>
>>> Regards,<br>
>>><br>
>>> Billy.<br>
Roman<br>
<br>
>>> _______________________________________________<br>
>>> cfe-dev mailing list<br>
>>> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
>>> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
><br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
</blockquote></div></div>