[cfe-dev] parentheses flag warning

Roman Lebedev via cfe-dev cfe-dev at lists.llvm.org
Mon May 18 10:49:18 PDT 2020


On Mon, May 18, 2020 at 8:44 PM Billy Araujo via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> Hi David,
>
> So I guess this is expected behaviour. Thanks.
>
> Regards,
>
> Billy.
>
>
> On Mon, May 18, 2020 at 6:39 PM David Blaikie <dblaikie at gmail.com> wrote:
>>
>> 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);")
>>
>> On Mon, May 18, 2020 at 6:53 AM Billy Araujo via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>>>
>>> -Wparentheses
>>>
>>> warns for line 3 but not for the ternary expression in line 2.
>>>
>>> 1 static void foo(int a, int b, int x) {
>>> 2    x = (x = 10) ? a : b;
>>> 3    if (x = 10) { x = a; } else { x = b; }
>>> 4 }
>>>
>>> Is this a bug?
This seems pretty correct to me.

You can't avoid braces on line 3, so those braces don't count as extra braces
to silence the diagnostic, while the situation on the line 2 is opposite,
no braces are needed there, so the braces count as silencers.

I.e. if line 2 *would* be diagnosed, i'd say that is a false-positive.

>>> Regards,
>>>
>>> Billy.
Roman

>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list