[LLVMbugs] [Bug 19063] New: No -Wparentheses warning for "if (a += b)"

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 6 01:11:10 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=19063

            Bug ID: 19063
           Summary: No -Wparentheses warning for "if (a += b)"
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chengniansun at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The clang trunk emits -Wparentheses warnings for "if (a |= b)" and "if(a = a +
b)", but not "if (a += b)"



$: cat s.c 
int b;
int f(int a) {
  if (a |= b)
    return 3;
  else if (a += b) /* <- no warning here*/ 
    return 2;
  else if (a = a + b) 
    return 4;
  else 
    return 1;
}
$: clang-trunk -Wparentheses -c s.c
s.c:3:9: warning: using the result of an assignment as a condition without
parentheses [-Wparentheses]
  if (a |= b)
      ~~^~~~
s.c:3:9: note: place parentheses around the assignment to silence this warning
  if (a |= b)
        ^
      (     )
s.c:3:9: note: use '!=' to turn this compound assignment into an inequality
comparison
  if (a |= b)
        ^~
        !=
s.c:7:14: warning: using the result of an assignment as a condition without
parentheses [-Wparentheses]
  else if (a = a + b) 
           ~~^~~~~~~
s.c:7:14: note: place parentheses around the assignment to silence this warning
  else if (a = a + b) 
             ^
           (        )
s.c:7:14: note: use '==' to turn this assignment into an equality comparison
  else if (a = a + b) 
             ^
             ==
2 warnings generated.
$:

-- 
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/20140306/f9ad3a4c/attachment.html>


More information about the llvm-bugs mailing list