@@ -123,8 +123,8 @@ static const Expr *getAcceptableCompoundsLHS(const BinaryOperator *BinOp) {
123123 if (const auto *DeclRefLHS =
124124 dyn_cast<DeclRefExpr>(BinOp->getLHS ()->IgnoreImpCasts ()))
125125 return DeclRefLHS;
126- else if (const auto *MemberLHS =
127- dyn_cast<MemberExpr>(BinOp->getLHS ()->IgnoreImpCasts ()))
126+ if (const auto *MemberLHS =
127+ dyn_cast<MemberExpr>(BinOp->getLHS ()->IgnoreImpCasts ()))
128128 return MemberLHS;
129129
130130 return nullptr ;
@@ -168,50 +168,68 @@ void BoolBitwiseOperationCheck::emitWarningAndChangeOperatorsIfPossible(
168168 .getDesugaredType (Ctx)
169169 .isVolatileQualified ();
170170 });
171- if (HasVolatileOperand)
172- return static_cast <void >(DiagEmitter ());
171+ if (HasVolatileOperand) {
172+ DiagEmitter ();
173+ return ;
174+ }
173175
174176 const bool HasSideEffects = BinOp->getRHS ()->HasSideEffects (
175177 Ctx, /* IncludePossibleEffects=*/ !StrictMode);
176- if (HasSideEffects)
177- return static_cast <void >(DiagEmitter ());
178+ if (HasSideEffects) {
179+ DiagEmitter ();
180+ return ;
181+ }
178182
179183 SourceLocation Loc = BinOp->getOperatorLoc ();
180184
181- if (Loc.isInvalid () || Loc.isMacroID ())
182- return static_cast <void >(IgnoreMacros || DiagEmitter ());
185+ if (Loc.isInvalid () || Loc.isMacroID ()) {
186+ IgnoreMacros || DiagEmitter ();
187+ return ;
188+ }
183189
184190 Loc = SM.getSpellingLoc (Loc);
185- if (Loc.isInvalid () || Loc.isMacroID ())
186- return static_cast <void >(IgnoreMacros || DiagEmitter ());
191+ if (Loc.isInvalid () || Loc.isMacroID ()) {
192+ IgnoreMacros || DiagEmitter ();
193+ return ;
194+ }
187195
188196 const CharSourceRange TokenRange = CharSourceRange::getTokenRange (Loc);
189- if (TokenRange.isInvalid ())
190- return static_cast <void >(IgnoreMacros || DiagEmitter ());
197+ if (TokenRange.isInvalid ()) {
198+ IgnoreMacros || DiagEmitter ();
199+ return ;
200+ }
191201
192202 const StringRef FixSpelling =
193203 translate (Lexer::getSourceText (TokenRange, SM, Ctx.getLangOpts ()));
194204
195- if (FixSpelling.empty ())
196- return static_cast <void >(DiagEmitter ());
205+ if (FixSpelling.empty ()) {
206+ DiagEmitter ();
207+ return ;
208+ }
197209
198210 FixItHint InsertEqual;
199211 if (BinOp->isCompoundAssignmentOp ()) {
200212 const auto *LHS = getAcceptableCompoundsLHS (BinOp);
201- if (!LHS)
202- return static_cast <void >(DiagEmitter ());
213+ if (!LHS) {
214+ DiagEmitter ();
215+ return ;
216+ }
203217 const SourceLocation LocLHS = LHS->getEndLoc ();
204- if (LocLHS.isInvalid () || LocLHS.isMacroID ())
205- return static_cast <void >(IgnoreMacros || DiagEmitter ());
218+ if (LocLHS.isInvalid () || LocLHS.isMacroID ()) {
219+ IgnoreMacros || DiagEmitter ();
220+ return ;
221+ }
206222 const SourceLocation InsertLoc =
207223 clang::Lexer::getLocForEndOfToken (LocLHS, 0 , SM, Ctx.getLangOpts ());
208- if (InsertLoc.isInvalid () || InsertLoc.isMacroID ())
209- return static_cast <void >(IgnoreMacros || DiagEmitter ());
224+ if (InsertLoc.isInvalid () || InsertLoc.isMacroID ()) {
225+ IgnoreMacros || DiagEmitter ();
226+ return ;
227+ }
210228 auto SourceText = static_cast <std::string>(Lexer::getSourceText (
211229 CharSourceRange::getTokenRange (LHS->getSourceRange ()), SM,
212230 Ctx.getLangOpts ()));
213231 llvm::erase_if (SourceText,
214- [](unsigned char ch ) { return std::isspace (ch ); });
232+ [](unsigned char Ch ) { return std::isspace (Ch ); });
215233 InsertEqual = FixItHint::CreateInsertion (InsertLoc, " = " + SourceText);
216234 }
217235
@@ -238,7 +256,7 @@ void BoolBitwiseOperationCheck::emitWarningAndChangeOperatorsIfPossible(
238256 } else if (BinOp->getOpcode () == BO_AndAssign && RHSOpcode == BO_LOr)
239257 SurroundedExpr = RHS;
240258
241- if (SurroundedExpr && isa <ParenExpr>(SurroundedExpr))
259+ if (isa_and_nonnull <ParenExpr>(SurroundedExpr))
242260 SurroundedExpr = nullptr ;
243261
244262 FixItHint InsertBrace1;
@@ -248,8 +266,10 @@ void BoolBitwiseOperationCheck::emitWarningAndChangeOperatorsIfPossible(
248266 const SourceLocation InsertSecondLoc = clang::Lexer::getLocForEndOfToken (
249267 SurroundedExpr->getEndLoc (), 0 , SM, Ctx.getLangOpts ());
250268 if (InsertFirstLoc.isInvalid () || InsertFirstLoc.isMacroID () ||
251- InsertSecondLoc.isInvalid () || InsertSecondLoc.isMacroID ())
252- return static_cast <void >(IgnoreMacros || DiagEmitter ());
269+ InsertSecondLoc.isInvalid () || InsertSecondLoc.isMacroID ()) {
270+ IgnoreMacros || DiagEmitter ();
271+ return ;
272+ }
253273 InsertBrace1 = FixItHint::CreateInsertion (InsertFirstLoc, " (" );
254274 InsertBrace2 = FixItHint::CreateInsertion (InsertSecondLoc, " )" );
255275 }
@@ -277,11 +297,11 @@ void BoolBitwiseOperationCheck::visitBinaryTreesNode(
277297}
278298
279299void BoolBitwiseOperationCheck::check (const MatchFinder::MatchResult &Result) {
280- const auto *binOpRoot = Result.Nodes .getNodeAs <BinaryOperator>(" binOpRoot" );
300+ const auto *BinOpRoot = Result.Nodes .getNodeAs <BinaryOperator>(" binOpRoot" );
281301 const SourceManager &SM = *Result.SourceManager ;
282302 ASTContext &Ctx = *Result.Context ;
283303 std::optional<bool > RootAssignsToBoolean = std::nullopt ;
284- visitBinaryTreesNode (binOpRoot , nullptr , SM, Ctx, RootAssignsToBoolean);
304+ visitBinaryTreesNode (BinOpRoot , nullptr , SM, Ctx, RootAssignsToBoolean);
285305}
286306
287307} // namespace clang::tidy::misc
0 commit comments