[llvm-bugs] [Bug 34180] New: Improve -Wparentheses for arbitrary bool contexts

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 13 22:03:05 PDT 2017


            Bug ID: 34180
           Summary: Improve -Wparentheses for arbitrary bool contexts
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chisophugis at gmail.com
                CC: llvm-bugs at lists.llvm.org


bool f(int x) {
    return x = 0; 

GCC gives:

<source>:2:16: warning: suggest parentheses around assignment used as truth
value [-Wparentheses]
     return x = 0; 

This would have caught a bug in r310794 (https://reviews.llvm.org/rL310794)

I don't know for sure, but from the reduced test case, it seems that GCC is
just seeing when an assignment is used in a bool-typed context? E.g. just
`bool(x = 0)` seems to trigger it. https://godbolt.org/g/HyBZHM
Looking at the two examples, it looks like ImplicitCastExpr to bool is probably
the thing to look for.
ImplicitCastExpr 0x4fce318 <col:12, col:16> '_Bool' <IntegralToBoolean>
ImplicitCastExpr 0x4fce578 <col:17, col:21> '_Bool' <IntegralToBoolean>

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170814/6c8266ad/attachment.html>

More information about the llvm-bugs mailing list