Skip to content

Commit 6a470bf

Browse files
authored
[clang-tidy][NFC] Remove redundant braces with clang-format 'RemoveBracesLLVM' (N/N) (#172754)
1 parent 031e9c9 commit 6a470bf

31 files changed

+84
-165
lines changed

clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S,
125125
if (const DeclStmt *CondVar = S->getConditionVariableDeclStmt())
126126
CondEndLoc = CondVar->getEndLoc();
127127

128-
if (!CondEndLoc.isValid()) {
128+
if (!CondEndLoc.isValid())
129129
return {};
130-
}
131130

132131
const SourceLocation PastCondEndLoc =
133132
Lexer::getLocForEndOfToken(CondEndLoc, 0, SM, LangOpts);

clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,18 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
278278
ReplacementText += ".empty()";
279279

280280
if (BinCmp) {
281-
if (BinCmp->getOperator() == OO_ExclaimEqual) {
281+
if (BinCmp->getOperator() == OO_ExclaimEqual)
282282
ReplacementText = "!" + ReplacementText;
283-
}
284283
Hint =
285284
FixItHint::CreateReplacement(BinCmp->getSourceRange(), ReplacementText);
286285
} else if (BinCmpTempl) {
287-
if (BinCmpTempl->getOpcode() == BinaryOperatorKind::BO_NE) {
286+
if (BinCmpTempl->getOpcode() == BinaryOperatorKind::BO_NE)
288287
ReplacementText = "!" + ReplacementText;
289-
}
290288
Hint = FixItHint::CreateReplacement(BinCmpTempl->getSourceRange(),
291289
ReplacementText);
292290
} else if (BinCmpRewritten) {
293-
if (BinCmpRewritten->getOpcode() == BinaryOperatorKind::BO_NE) {
291+
if (BinCmpRewritten->getOpcode() == BinaryOperatorKind::BO_NE)
294292
ReplacementText = "!" + ReplacementText;
295-
}
296293
Hint = FixItHint::CreateReplacement(BinCmpRewritten->getSourceRange(),
297294
ReplacementText);
298295
} else if (BinaryOp) { // Determine the correct transformation.
@@ -400,10 +397,9 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
400397
Result.Nodes.getNodeAs<CXXDependentScopeMemberExpr>(
401398
"MemberExpr"))
402399
Diag << DependentExpr->getMember();
403-
else if (const auto *ME =
404-
Result.Nodes.getNodeAs<MemberExpr>("MemberExpr")) {
400+
else if (const auto *ME = Result.Nodes.getNodeAs<MemberExpr>("MemberExpr"))
405401
Diag << ME->getMemberNameInfo().getName();
406-
} else
402+
else
407403
Diag << "unknown method";
408404
Diag << Hint;
409405
} else {

clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ DuplicateIncludeCallbacks::DuplicateIncludeCallbacks(
8080
Files.emplace_back();
8181

8282
AllowedRegexes.reserve(IgnoredList.size());
83-
for (const StringRef &It : IgnoredList) {
83+
for (const StringRef &It : IgnoredList)
8484
if (!It.empty())
8585
AllowedRegexes.emplace_back(It);
86-
}
8786
}
8887

8988
void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,

clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ static const DeclRefExpr *findUsage(const Stmt *Node, int64_t DeclIdentifier) {
5353
if (DeclRef->getDecl()->getID() == DeclIdentifier)
5454
return DeclRef;
5555
} else {
56-
for (const Stmt *ChildNode : Node->children()) {
56+
for (const Stmt *ChildNode : Node->children())
5757
if (const DeclRefExpr *Result = findUsage(ChildNode, DeclIdentifier))
5858
return Result;
59-
}
6059
}
6160
return nullptr;
6261
}
@@ -70,11 +69,10 @@ findUsageRange(const Stmt *Node,
7069
if (llvm::is_contained(DeclIdentifiers, DeclRef->getDecl()->getID()))
7170
return DeclRef;
7271
} else {
73-
for (const Stmt *ChildNode : Node->children()) {
72+
for (const Stmt *ChildNode : Node->children())
7473
if (const DeclRefExpr *Result =
7574
findUsageRange(ChildNode, DeclIdentifiers))
7675
return Result;
77-
}
7876
}
7977
return nullptr;
8078
}

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,9 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
319319

320320
const char *const PosList[] = {strchr(Begin, '='), strchr(Begin, ';'),
321321
strchr(Begin, ','), strchr(Begin, ')'), EOL};
322-
for (const auto &Pos : PosList) {
322+
for (const auto &Pos : PosList)
323323
if (Pos > Begin)
324324
EOL = std::min(EOL, Pos);
325-
}
326325

327326
StrLen = EOL - Begin;
328327
std::string TypeName;
@@ -340,18 +339,15 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
340339
"virtual"};
341340

342341
// Remove keywords
343-
for (const StringRef Kw : Keywords) {
344-
for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;) {
342+
for (const StringRef Kw : Keywords)
343+
for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;)
345344
Type.replace(Pos, Kw.size(), "");
346-
}
347-
}
348345
TypeName = Type.erase(0, Type.find_first_not_of(' '));
349346

350347
// Remove template parameters
351348
const size_t Pos = Type.find('<');
352-
if (Pos != std::string::npos) {
349+
if (Pos != std::string::npos)
353350
TypeName = Type.erase(Pos, Type.size() - Pos);
354-
}
355351

356352
// Replace spaces with single space.
357353
for (size_t Pos = 0; (Pos = Type.find(" ", Pos)) != std::string::npos;
@@ -699,10 +695,9 @@ size_t IdentifierNamingCheck::HungarianNotation::getAsteriskCount(
699695
const std::string &TypeName) const {
700696
size_t Pos = TypeName.find('*');
701697
size_t Count = 0;
702-
for (; Pos < TypeName.length(); Pos++, Count++) {
698+
for (; Pos < TypeName.length(); Pos++, Count++)
703699
if ('*' != TypeName[Pos])
704700
break;
705-
}
706701
return Count;
707702
}
708703

@@ -941,9 +936,8 @@ std::string IdentifierNamingCheck::fixupWithCase(
941936
if (Words.empty())
942937
return Name.str();
943938

944-
if (IdentifierNamingCheck::HungarianPrefixType::HPT_Off != Style.HPType) {
939+
if (IdentifierNamingCheck::HungarianPrefixType::HPT_Off != Style.HPType)
945940
HungarianNotation.removeDuplicatedPrefix(Words, HNOption);
946-
}
947941

948942
SmallString<128> Fixup;
949943
switch (Case) {
@@ -1199,9 +1193,8 @@ StyleKind IdentifierNamingCheck::findStyleKind(
11991193
if (const auto *Decl = dyn_cast<FieldDecl>(D)) {
12001194
if (CheckAnonFieldInParentScope) {
12011195
const RecordDecl *Record = Decl->getParent();
1202-
if (Record->isAnonymousStructOrUnion()) {
1196+
if (Record->isAnonymousStructOrUnion())
12031197
return findStyleKindForAnonField(Decl, NamingStyles);
1204-
}
12051198
}
12061199

12071200
return findStyleKindForField(Decl, Decl->getType(), NamingStyles);
@@ -1240,9 +1233,8 @@ StyleKind IdentifierNamingCheck::findStyleKind(
12401233
return SK_Invalid;
12411234
}
12421235

1243-
if (const auto *Decl = dyn_cast<VarDecl>(D)) {
1236+
if (const auto *Decl = dyn_cast<VarDecl>(D))
12441237
return findStyleKindForVar(Decl, Decl->getType(), NamingStyles);
1245-
}
12461238

12471239
if (const auto *Decl = dyn_cast<CXXMethodDecl>(D)) {
12481240
if (Decl->isMain() || !Decl->isUserProvided() ||
@@ -1458,13 +1450,11 @@ StyleKind IdentifierNamingCheck::findStyleKindForAnonField(
14581450

14591451
const QualType Type = AnonField->getType();
14601452

1461-
if (const auto *F = dyn_cast<FieldDecl>(IFD->chain().front())) {
1453+
if (const auto *F = dyn_cast<FieldDecl>(IFD->chain().front()))
14621454
return findStyleKindForField(F, Type, NamingStyles);
1463-
}
14641455

1465-
if (const auto *V = IFD->getVarDecl()) {
1456+
if (const auto *V = IFD->getVarDecl())
14661457
return findStyleKindForVar(V, Type, NamingStyles);
1467-
}
14681458

14691459
return SK_Invalid;
14701460
}

clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,23 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
9898

9999
std::string StartLocInsertion;
100100

101-
if (NeedOuterParens) {
101+
if (NeedOuterParens)
102102
StartLocInsertion += "(";
103-
}
104-
if (NeedInnerParens) {
103+
if (NeedInnerParens)
105104
StartLocInsertion += "(";
106-
}
107105

108-
if (!StartLocInsertion.empty()) {
106+
if (!StartLocInsertion.empty())
109107
Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(), StartLocInsertion);
110-
}
111108

112109
std::string EndLocInsertion;
113110

114-
if (NeedInnerParens) {
111+
if (NeedInnerParens)
115112
EndLocInsertion += ")";
116-
}
117113

118-
if (InvertComparison) {
114+
if (InvertComparison)
119115
EndLocInsertion += " == ";
120-
} else {
116+
else
121117
EndLocInsertion += " != ";
122-
}
123118

124119
const StringRef ZeroLiteral = getZeroLiteralToCompareWithForType(
125120
Cast->getCastKind(), SubExpr->getType(), Context);
@@ -129,9 +124,8 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
129124
else
130125
EndLocInsertion += ZeroLiteral;
131126

132-
if (NeedOuterParens) {
127+
if (NeedOuterParens)
133128
EndLocInsertion += ")";
134-
}
135129

136130
const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
137131
Cast->getEndLoc(), 0, Context.getSourceManager(), Context.getLangOpts());
@@ -140,28 +134,23 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
140134

141135
static StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
142136
ASTContext &Context) {
143-
if (isNULLMacroExpansion(Expression, Context)) {
137+
if (isNULLMacroExpansion(Expression, Context))
144138
return "false";
145-
}
146139

147-
if (const auto *IntLit =
148-
dyn_cast<IntegerLiteral>(Expression->IgnoreParens())) {
140+
if (const auto *IntLit = dyn_cast<IntegerLiteral>(Expression->IgnoreParens()))
149141
return (IntLit->getValue() == 0) ? "false" : "true";
150-
}
151142

152143
if (const auto *FloatLit = dyn_cast<FloatingLiteral>(Expression)) {
153144
llvm::APFloat FloatLitAbsValue = FloatLit->getValue();
154145
FloatLitAbsValue.clearSign();
155146
return (FloatLitAbsValue.bitcastToAPInt() == 0) ? "false" : "true";
156147
}
157148

158-
if (const auto *CharLit = dyn_cast<CharacterLiteral>(Expression)) {
149+
if (const auto *CharLit = dyn_cast<CharacterLiteral>(Expression))
159150
return (CharLit->getValue() == 0) ? "false" : "true";
160-
}
161151

162-
if (isa<StringLiteral>(Expression->IgnoreCasts())) {
152+
if (isa<StringLiteral>(Expression->IgnoreCasts()))
163153
return "true";
164-
}
165154

166155
return {};
167156
}
@@ -217,15 +206,13 @@ getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral,
217206
}
218207

219208
if (DestType->isFloatingType()) {
220-
if (ASTContext::hasSameType(DestType, Context.FloatTy)) {
209+
if (ASTContext::hasSameType(DestType, Context.FloatTy))
221210
return BoolLiteral->getValue() ? "1.0f" : "0.0f";
222-
}
223211
return BoolLiteral->getValue() ? "1.0" : "0.0";
224212
}
225213

226-
if (DestType->isUnsignedIntegerType()) {
214+
if (DestType->isUnsignedIntegerType())
227215
return BoolLiteral->getValue() ? "1u" : "0u";
228-
}
229216
return BoolLiteral->getValue() ? "1" : "0";
230217
}
231218

clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,9 @@ getParameterSourceDeclaration(const FunctionDecl *OriginalDeclaration) {
184184
if (OriginalDeclaration->isThisDeclarationADefinition())
185185
return OriginalDeclaration;
186186

187-
for (const FunctionDecl *OtherDeclaration : OriginalDeclaration->redecls()) {
188-
if (OtherDeclaration->isThisDeclarationADefinition()) {
187+
for (const FunctionDecl *OtherDeclaration : OriginalDeclaration->redecls())
188+
if (OtherDeclaration->isThisDeclarationADefinition())
189189
return OtherDeclaration;
190-
}
191-
}
192190

193191
// No definition found, so return original declaration.
194192
return OriginalDeclaration;

clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ bool MagicNumbersCheck::isConstant(const MatchFinder::MatchResult &Result,
187187
}
188188

189189
bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
190-
if (Literal->getType()->isBitIntType()) {
190+
if (Literal->getType()->isBitIntType())
191191
return true;
192-
}
193192
const llvm::APInt IntValue = Literal->getValue();
194193
const int64_t Value = IntValue.getZExtValue();
195194
if (Value == 0)

clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
178178

179179
// Look through deref of this.
180180
if (const auto *UnOp = dyn_cast_or_null<UnaryOperator>(Parent)) {
181-
if (UnOp->getOpcode() == UO_Deref) {
181+
if (UnOp->getOpcode() == UO_Deref)
182182
Parent = getParentExprIgnoreParens(UnOp);
183-
}
184183
}
185184

186185
// It's okay to

clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
110110
// Currently for nested namespace (n1::n2::...) the AST matcher will match foo
111111
// then bar instead of a single match. So if we got a nested namespace we have
112112
// to skip the next ones.
113-
for (const SourceLocation &EndOfNameLocation : Ends) {
113+
for (const SourceLocation &EndOfNameLocation : Ends)
114114
if (Sources.isBeforeInTranslationUnit(ND->getLocation(), EndOfNameLocation))
115115
return;
116-
}
117116

118117
std::optional<std::string> NamespaceNameAsWritten =
119118
getNamespaceNameAsWritten(LBraceLoc, Sources, getLangOpts());

0 commit comments

Comments
 (0)