Skip to content

Commit f751713

Browse files
committed
review
1 parent 0ff272d commit f751713

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,45 +89,45 @@ void BoolBitwiseOperationCheck::check(const MatchFinder::MatchResult &Result) {
8989
return E->IgnoreImpCasts()->getType().isVolatileQualified();
9090
});
9191
if (HasVolatileOperand)
92-
return (void)DiagEmitter();
92+
return static_cast<void>(DiagEmitter());
9393

9494
const bool HasSideEffects = MatchedExpr->getRHS()->HasSideEffects(
9595
*Result.Context, /*IncludePossibleEffects=*/!StrictMode);
9696
if (HasSideEffects)
97-
return (void)DiagEmitter();
97+
return static_cast<void>(DiagEmitter());
9898

9999
SourceLocation Loc = MatchedExpr->getOperatorLoc();
100100

101101
if (Loc.isInvalid() || Loc.isMacroID())
102-
return void(IgnoreMacros || DiagEmitter());
102+
return static_cast<void>(IgnoreMacros || DiagEmitter());
103103

104104
Loc = Result.SourceManager->getSpellingLoc(Loc);
105105
if (Loc.isInvalid() || Loc.isMacroID())
106-
return void(IgnoreMacros || DiagEmitter());
106+
return static_cast<void>(IgnoreMacros || DiagEmitter());
107107

108108
const CharSourceRange TokenRange = CharSourceRange::getTokenRange(Loc);
109109
if (TokenRange.isInvalid())
110-
return void(IgnoreMacros || DiagEmitter());
110+
return static_cast<void>(IgnoreMacros || DiagEmitter());
111111

112112
const StringRef FixSpelling = translate(Lexer::getSourceText(
113113
TokenRange, *Result.SourceManager, Result.Context->getLangOpts()));
114114

115115
if (FixSpelling.empty())
116-
return (void)DiagEmitter();
116+
return static_cast<void>(DiagEmitter());
117117

118118
FixItHint InsertEqual;
119119
if (MatchedExpr->isCompoundAssignmentOp()) {
120120
const auto *DeclRefLHS =
121121
dyn_cast<DeclRefExpr>(MatchedExpr->getLHS()->IgnoreImpCasts());
122122
if (!DeclRefLHS)
123-
return (void)DiagEmitter();
123+
return static_cast<void>(DiagEmitter());
124124
const SourceLocation LocLHS = DeclRefLHS->getEndLoc();
125125
if (LocLHS.isInvalid() || LocLHS.isMacroID())
126-
return void(IgnoreMacros || DiagEmitter());
126+
return static_cast<void>(IgnoreMacros || DiagEmitter());
127127
const SourceLocation InsertLoc = clang::Lexer::getLocForEndOfToken(
128128
LocLHS, 0, *Result.SourceManager, Result.Context->getLangOpts());
129129
if (InsertLoc.isInvalid() || InsertLoc.isMacroID())
130-
return void(IgnoreMacros || DiagEmitter());
130+
return static_cast<void>(IgnoreMacros || DiagEmitter());
131131
InsertEqual = FixItHint::CreateInsertion(
132132
InsertLoc, " = " + DeclRefLHS->getDecl()->getNameAsString());
133133
}
@@ -149,7 +149,7 @@ void BoolBitwiseOperationCheck::check(const MatchFinder::MatchResult &Result) {
149149
if ((MatchedExpr->getOpcode() == BO_Or && ParentOpcode == BO_LAnd) ||
150150
(MatchedExpr->getOpcode() == BO_And &&
151151
llvm::is_contained({BO_Xor, BO_Or}, ParentOpcode))) {
152-
const auto *Side = Parent->getLHS()->IgnoreParenImpCasts() == MatchedExpr
152+
const Expr *Side = Parent->getLHS()->IgnoreParenImpCasts() == MatchedExpr
153153
? Parent->getLHS()
154154
: Parent->getRHS();
155155
SurroundedExpr = Side->IgnoreImpCasts();
@@ -160,15 +160,16 @@ void BoolBitwiseOperationCheck::check(const MatchFinder::MatchResult &Result) {
160160
if (SurroundedExpr && isa<ParenExpr>(SurroundedExpr))
161161
SurroundedExpr = nullptr;
162162

163-
FixItHint InsertBrace1, InsertBrace2;
163+
FixItHint InsertBrace1;
164+
FixItHint InsertBrace2;
164165
if (SurroundedExpr) {
165166
const SourceLocation InsertFirstLoc = SurroundedExpr->getBeginLoc();
166167
const SourceLocation InsertSecondLoc = clang::Lexer::getLocForEndOfToken(
167168
SurroundedExpr->getEndLoc(), 0, *Result.SourceManager,
168169
Result.Context->getLangOpts());
169170
if (InsertFirstLoc.isInvalid() || InsertFirstLoc.isMacroID() ||
170171
InsertSecondLoc.isInvalid() || InsertSecondLoc.isMacroID())
171-
return void(IgnoreMacros || DiagEmitter());
172+
return static_cast<void>(IgnoreMacros || DiagEmitter());
172173
InsertBrace1 = FixItHint::CreateInsertion(InsertFirstLoc, "(");
173174
InsertBrace2 = FixItHint::CreateInsertion(InsertSecondLoc, ")");
174175
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ to implicit integer conversions and missed short-circuit evaluation.
2020
// error handling
2121
}
2222
23-
These 3 warnings suggest to assign result of logical ``||`` operation instead
24-
of using ``|=`` operator:
23+
These 3 warnings suggest assigning the result of a logical ``||`` operation
24+
instead of using the ``|=`` operator:
2525

2626
.. code-block:: c++
2727

@@ -57,6 +57,6 @@ Options
5757

5858
.. option:: IgnoreMacros
5959

60-
Enabling this option hides the warning message in a situation where
61-
it is not possible to change a bitwise operator to a logical one due
62-
to a macro in the expression body. Default value is `false`.
60+
This option disables the warning if a macro inside the expression body
61+
prevents replacing a bitwise operator with a logical one. Default value
62+
is `false`.

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
// RUN: -config="{CheckOptions: { \
33
// RUN: misc-bool-bitwise-operation.IgnoreMacros: true }}"
44

5-
#define MY_OR |
6-
#define MY_AND &
7-
#define MY_OR_ASSIGN |=
8-
#define MY_AND_ASSIGN &=
9-
#define MY_LOG_AND &&
10-
115
#define CAT(a, b) a ## b
126
#define IDENT(a) a
137

0 commit comments

Comments
 (0)