[cfe-dev] parentheses flag warning

Billy Araujo via cfe-dev cfe-dev at lists.llvm.org
Mon May 18 10:58:56 PDT 2020


Hi David,

Actually the situation you present foo(x =5); is interesting because gcc 10
flags this while clang 10 doesn't:

https://godbolt.org/z/NXUPrU

warning: suggest parentheses around assignment used as truth value

@Roman. Thanks for the further explanation. That makes sense.

Regards,

Billy.



On Mon, May 18, 2020 at 6:49 PM Roman Lebedev <lebedev.ri at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200518/e13825e6/attachment-0001.html>


More information about the cfe-dev mailing list