]> granicus.if.org Git - clang/commit
Add -Wbitwise-conditional-parentheses to warn on mixing '|' and '&' with "?:"
authorRichard Trieu <rtrieu@google.com>
Sat, 19 Oct 2019 01:47:49 +0000 (01:47 +0000)
committerRichard Trieu <rtrieu@google.com>
Sat, 19 Oct 2019 01:47:49 +0000 (01:47 +0000)
commitae3e9c83d470f2f2c4fa84e66c0451abcbfb3598
treee40f515caace6e493e49953ad72cd3ca630f14d4
parent56ddb2a69c92a417a93e8ccf3f8fe1ce047c78e3
Add -Wbitwise-conditional-parentheses to warn on mixing '|' and '&' with "?:"

Extend -Wparentheses to cover mixing bitwise-and and bitwise-or with the
conditional operator. There's two main cases seen with this:

unsigned bits1 = 0xf0 | cond ? 0x4 : 0x1;
unsigned bits2 = cond1 ? 0xf0 : 0x10 | cond2 ? 0x5 : 0x2;

// Intended order of evaluation:
unsigned bits1 = 0xf0 | (cond ? 0x4 : 0x1);
unsigned bits2 = (cond1 ? 0xf0 : 0x10) | (cond2 ? 0x5 : 0x2);

// Actual order of evaluation:
unsigned bits1 = (0xf0 | cond) ? 0x4 : 0x1;
unsigned bits2 = cond1 ? 0xf0 : ((0x10 | cond2) ? 0x5 : 0x2);

Differential Revision: https://reviews.llvm.org/D66043

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375326 91177308-0d34-0410-b5e6-96231b3b80d8
docs/ReleaseNotes.rst
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/Sema/parentheses.c