Skip to content

Commit c01dfbe

Browse files
committed
simplify
1 parent 75a5399 commit c01dfbe

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,7 @@ static bool assignsToBoolean(const BinaryOperator *BinOp, ASTContext *AC) {
3535
auto Parents = AC->getParents(*BinOp);
3636

3737
for (const auto &Parent : Parents) {
38-
const auto *ParentNoParen = ignoreParensTowardsTheRoot(&Parent, AC);
39-
// Special handling for `template<bool bb=true|1>` cases
40-
if (const auto *D = ParentNoParen->get<Decl>()) {
41-
if (const auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(D)) {
42-
if (NTTPD->getType().getDesugaredType(*AC)->isBooleanType())
43-
return true;
44-
}
45-
}
46-
47-
if (const auto *S = ParentNoParen->get<Stmt>()) {
38+
if (const auto *S = ignoreParensTowardsTheRoot(&Parent, AC)->get<Stmt>()) {
4839
if (const auto *ICE = dyn_cast<ImplicitCastExpr>(S)) {
4940
if (ICE->getType().getDesugaredType(*AC)->isBooleanType())
5041
return true;

clang-tools-extra/test/clang-tidy/checkers/misc/bool-bitwise-operation-not-only-bool-operand.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ void general(unsigned flags, bool value) {
1111

1212
void take(bool value) {}
1313

14-
template<bool bb = true | 1>
15-
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
16-
// CHECK-FIXES: template<bool bb = true || 1>
14+
// FIXME: implement `template<bool bb=true|1>` cases
15+
1716
void assign_to_boolean(unsigned flags, bool value) {
1817
struct A { bool a = true | 1; };
1918
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
@@ -50,9 +49,6 @@ void assign_to_boolean(unsigned flags, bool value) {
5049
// CHECK-FIXES: result = (flags << 1) || (flags << 2) || (flags << 4) || value;
5150
}
5251

53-
template<bool bb = (true | 1)>
54-
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
55-
// CHECK-FIXES: template<bool bb = (true || 1)>
5652
void assign_to_boolean_parens(unsigned flags, bool value) {
5753
struct A { bool a = (true | 1); };
5854
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
@@ -89,9 +85,6 @@ void assign_to_boolean_parens(unsigned flags, bool value) {
8985
// CHECK-FIXES: result = ((flags << 1) || (flags << 2) || (flags << 4) || value);
9086
}
9187

92-
template<bool bb = ((true | 1))>
93-
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
94-
// CHECK-FIXES: template<bool bb = ((true || 1))>
9588
void assign_to_boolean_parens2(unsigned flags, bool value) {
9689
struct A { bool a = ((true | 1)); };
9790
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
@@ -129,9 +122,6 @@ void assign_to_boolean_parens2(unsigned flags, bool value) {
129122
}
130123

131124
// functional cast
132-
template<bool bb = bool(true | 1)>
133-
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
134-
// CHECK-FIXES: template<bool bb = bool(true || 1)>
135125
void assign_to_boolean_fcast(unsigned flags, bool value) {
136126
struct A { bool a = bool(true | 1); };
137127
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
@@ -169,9 +159,6 @@ void assign_to_boolean_fcast(unsigned flags, bool value) {
169159
}
170160

171161
// C-style cast
172-
template<bool bb = (bool)(true | 1)>
173-
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
174-
// CHECK-FIXES: template<bool bb = (bool)(true || 1)>
175162
void assign_to_boolean_ccast(unsigned flags, bool value) {
176163
struct A { bool a = (bool)(true | 1); };
177164
// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
@@ -209,9 +196,6 @@ void assign_to_boolean_ccast(unsigned flags, bool value) {
209196
}
210197

211198
// static_cast
212-
template<bool bb = static_cast<bool>(true | 1)>
213-
// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]
214-
// CHECK-FIXES: template<bool bb = static_cast<bool>(true || 1)>
215199
void assign_to_boolean_scast(unsigned flags, bool value) {
216200
struct A { bool a = static_cast<bool>(true | 1); };
217201
// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: use logical operator '||' for boolean semantics instead of bitwise operator '|' [misc-bool-bitwise-operation]

0 commit comments

Comments
 (0)