Skip to content

Commit cb9d520

Browse files
committed
Simplify the warning message
1 parent dfa7ce4 commit cb9d520

10 files changed

+83
-95
lines changed

clang-tools-extra/clang-tidy/misc/BoolBitwiseOperationCheck.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ static bool assignsToBoolean(const BinaryOperator *BinOp, ASTContext *AC) {
5555
return false;
5656
}
5757

58-
static const NamedDecl *
59-
getLHSNamedDeclIfCompoundAssign(const BinaryOperator *BO) {
60-
if (BO->isCompoundAssignmentOp()) {
61-
if (const auto *DeclRefLHS = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreImpCasts()))
62-
return DeclRefLHS->getDecl();
63-
else if (const auto *MemberLHS = dyn_cast<MemberExpr>(BO->getLHS()->IgnoreImpCasts()))
64-
return MemberLHS->getMemberDecl();
65-
}
66-
return nullptr;
67-
}
68-
6958
constexpr std::array<std::pair<llvm::StringRef, llvm::StringRef>, 8U>
7059
OperatorsTransformation{{{"|", "||"},
7160
{"|=", "||"},
@@ -169,10 +158,9 @@ void BoolBitwiseOperationCheck::emitWarningAndChangeOperatorsIfPossible(
169158
const BinaryOperator *BinOp, const BinaryOperator *ParentBinOp,
170159
const clang::SourceManager &SM, clang::ASTContext &Ctx) {
171160
auto DiagEmitter = [BinOp, this] {
172-
const NamedDecl *ND = getLHSNamedDeclIfCompoundAssign(BinOp);
173161
return diag(BinOp->getOperatorLoc(),
174-
"use logical operator '%0' for boolean %select{%select{member|variable}2 %3|semantics}1 instead of bitwise operator '%4'")
175-
<< translate(BinOp->getOpcodeStr()) << (ND == nullptr) << (!isa<MemberExpr>(BinOp->getLHS()->IgnoreImpCasts())) << ND
162+
"use logical operator '%0' for boolean semantics instead of bitwise operator '%1'")
163+
<< translate(BinOp->getOpcodeStr())
176164
<< BinOp->getOpcodeStr();
177165
};
178166

clang-tools-extra/docs/clang-tidy/checks/misc/bool-bitwise-operation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ to implicit integer conversions and missed short-circuit evaluation.
1313
.. code-block:: c++
1414

1515
bool invalid = false;
16-
invalid |= x > limit.x; // warning: use logical operator '||' for boolean variable 'invalid' instead of bitwise operator '|='
17-
invalid |= y > limit.y; // warning: use logical operator '||' for boolean variable 'invalid' instead of bitwise operator '|='
18-
invalid |= z > limit.z; // warning: use logical operator '||' for boolean variable 'invalid' instead of bitwise operator '|='
16+
invalid |= x > limit.x; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
17+
invalid |= y > limit.y; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
18+
invalid |= z > limit.z; // warning: use logical operator '||' for boolean semantics instead of bitwise operator '|='
1919
if (invalid) {
2020
// error handling
2121
}

clang-tools-extra/test/clang-tidy/checkers/misc/bool-bitwise-operation-change-possible-side-effect.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ void bad_possible_side_effects() {
1616
// CHECK-FIXES: a && function_with_possible_side_effects();
1717

1818
a |= function_with_possible_side_effects();
19-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean variable 'a' instead of bitwise operator '|=' [misc-bool-bitwise-operation]
19+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|=' [misc-bool-bitwise-operation]
2020
// CHECK-FIXES: a = a || function_with_possible_side_effects();
2121

2222
a &= function_with_possible_side_effects();
23-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean variable 'a' instead of bitwise operator '&=' [misc-bool-bitwise-operation]
23+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean semantics instead of bitwise operator '&=' [misc-bool-bitwise-operation]
2424
// CHECK-FIXES: a = a && function_with_possible_side_effects();
2525

2626
bool c = true;
2727

2828
a &= function_with_possible_side_effects() && c;
29-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean variable 'a' instead of bitwise operator '&=' [misc-bool-bitwise-operation]
29+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean semantics instead of bitwise operator '&=' [misc-bool-bitwise-operation]
3030
// CHECK-FIXES: a = a && function_with_possible_side_effects() && c;
3131

3232
a &= b && function_with_possible_side_effects();
33-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean variable 'a' instead of bitwise operator '&=' [misc-bool-bitwise-operation]
33+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean semantics instead of bitwise operator '&=' [misc-bool-bitwise-operation]
3434
// CHECK-FIXES: a = a && b && function_with_possible_side_effects();
3535

3636
a |= function_with_possible_side_effects() || c;
37-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean variable 'a' instead of bitwise operator '|=' [misc-bool-bitwise-operation]
37+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|=' [misc-bool-bitwise-operation]
3838
// CHECK-FIXES: a = a || function_with_possible_side_effects() || c;
3939

4040
a |= b || function_with_possible_side_effects();
41-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean variable 'a' instead of bitwise operator '|=' [misc-bool-bitwise-operation]
41+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|=' [misc-bool-bitwise-operation]
4242
// CHECK-FIXES: a = a || b || function_with_possible_side_effects();
4343
}
4444

@@ -55,28 +55,28 @@ void bad_definitely_side_effects() {
5555
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:{{.*}}: note: FIX-IT applied suggested code changes
5656

5757
a |= (acc++, b);
58-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean variable 'a' instead of bitwise operator '|=' [misc-bool-bitwise-operation]
58+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|=' [misc-bool-bitwise-operation]
5959
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:{{.*}}: note: FIX-IT applied suggested code changes
6060

6161
a &= (acc++, b);
62-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean variable 'a' instead of bitwise operator '&=' [misc-bool-bitwise-operation]
62+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean semantics instead of bitwise operator '&=' [misc-bool-bitwise-operation]
6363
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:{{.*}}: note: FIX-IT applied suggested code changes
6464

6565
bool c = true;
6666

6767
a &= (acc++, b) && c;
68-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean variable 'a' instead of bitwise operator '&=' [misc-bool-bitwise-operation]
68+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean semantics instead of bitwise operator '&=' [misc-bool-bitwise-operation]
6969
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:{{.*}}: note: FIX-IT applied suggested code changes
7070

7171
a &= b && (acc++, c);
72-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean variable 'a' instead of bitwise operator '&=' [misc-bool-bitwise-operation]
72+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean semantics instead of bitwise operator '&=' [misc-bool-bitwise-operation]
7373
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:{{.*}}: note: FIX-IT applied suggested code changes
7474

7575
a |= (acc++, b) || c;
76-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean variable 'a' instead of bitwise operator '|=' [misc-bool-bitwise-operation]
76+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|=' [misc-bool-bitwise-operation]
7777
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:{{.*}}: note: FIX-IT applied suggested code changes
7878

7979
a |= b || (acc++, c);
80-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean variable 'a' instead of bitwise operator '|=' [misc-bool-bitwise-operation]
80+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|=' [misc-bool-bitwise-operation]
8181
// CHECK-MESSAGES-NOT: :[[@LINE-2]]:{{.*}}: note: FIX-IT applied suggested code changes
8282
}

clang-tools-extra/test/clang-tidy/checkers/misc/bool-bitwise-operation-ignore-macros.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ void bad_in_macro() {
4848

4949
// insert ` = a`- GOOD
5050
b &= CAT(a, b);
51-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean variable 'b' instead of bitwise operator '&=' [misc-bool-bitwise-operation]
51+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use logical operator '&&' for boolean semantics instead of bitwise operator '&=' [misc-bool-bitwise-operation]
5252
// CHECK-FIXES: b = b && CAT(a, b);
5353
}

0 commit comments

Comments
 (0)