Skip to content

Commit 842e591

Browse files
authored
[clang-tidy][NFC] fix clang-tidy warnings in clang-tools-extra/clang-tidy directory (#136097)
Mostly stylistic changes to `clang-tidy` source code. Command run: `python3 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -p build/ -j $(nproc) clang-tools-extra/clang-tidy`
1 parent f0cc50c commit 842e591

16 files changed

+126
-126
lines changed

clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ using namespace ::clang::transformer;
2121

2222
namespace clang::tidy::abseil {
2323

24-
RewriteRuleWith<std::string> CleanupCtadCheckImpl() {
25-
auto warning_message = cat("prefer absl::Cleanup's class template argument "
26-
"deduction pattern in C++17 and higher");
24+
RewriteRuleWith<std::string> cleanupCtadCheckImpl() {
25+
auto WarningMessage = cat("prefer absl::Cleanup's class template argument "
26+
"deduction pattern in C++17 and higher");
2727

2828
return makeRule(
2929
declStmt(hasSingleDecl(varDecl(
@@ -34,10 +34,10 @@ RewriteRuleWith<std::string> CleanupCtadCheckImpl() {
3434
.bind("make_cleanup_call")))))),
3535
{changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
3636
changeTo(node("make_cleanup_call"), cat(callArgs("make_cleanup_call")))},
37-
warning_message);
37+
WarningMessage);
3838
}
3939

4040
CleanupCtadCheck::CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
41-
: utils::TransformerClangTidyCheck(CleanupCtadCheckImpl(), Name, Context) {}
41+
: utils::TransformerClangTidyCheck(cleanupCtadCheckImpl(), Name, Context) {}
4242

4343
} // namespace clang::tidy::abseil

clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
250250

251251
if (!llvm::all_of(llvm::zip(CompStmt1->body(), CompStmt2->body()),
252252
[&Ctx, IgnoreSideEffects](
253-
std::tuple<const Stmt *, const Stmt *> stmtPair) {
254-
const Stmt *stmt0 = std::get<0>(stmtPair);
255-
const Stmt *stmt1 = std::get<1>(stmtPair);
256-
return isIdenticalStmt(Ctx, stmt0, stmt1,
253+
std::tuple<const Stmt *, const Stmt *> StmtPair) {
254+
const Stmt *Stmt0 = std::get<0>(StmtPair);
255+
const Stmt *Stmt1 = std::get<1>(StmtPair);
256+
return isIdenticalStmt(Ctx, Stmt0, Stmt1,
257257
IgnoreSideEffects);
258258
})) {
259259
return false;
@@ -477,7 +477,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
477477

478478
if (const auto *IS = Result.Nodes.getNodeAs<IfStmt>("ifWithDescendantIf")) {
479479
const Stmt *Then = IS->getThen();
480-
auto CS = dyn_cast<CompoundStmt>(Then);
480+
const auto *CS = dyn_cast<CompoundStmt>(Then);
481481
if (CS && (!CS->body_empty())) {
482482
const auto *InnerIf = dyn_cast<IfStmt>(*CS->body_begin());
483483
if (InnerIf && isIdenticalStmt(Context, IS->getCond(), InnerIf->getCond(),

clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ bool isCXXOnlyStmt(const Stmt *S) {
301301
/// It is unspecified which call is found if multiple calls exist, but the order
302302
/// should be deterministic (depend only on the AST).
303303
Expr *findCallExpr(const CallGraphNode *Caller, const CallGraphNode *Callee) {
304-
auto FoundCallee = llvm::find_if(
304+
const auto *FoundCallee = llvm::find_if(
305305
Caller->callees(), [Callee](const CallGraphNode::CallRecord &Call) {
306306
return Call.Callee == Callee;
307307
});

clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
9999
if (Result.Nodes.getNodeAs<Expr>("parent"))
100100
return;
101101

102-
const auto PParentStmtExpr = Result.Nodes.getNodeAs<Expr>("stexpr");
103-
const auto ParentCompStmt = Result.Nodes.getNodeAs<CompoundStmt>("parent");
102+
const auto *PParentStmtExpr = Result.Nodes.getNodeAs<Expr>("stexpr");
103+
const auto *ParentCompStmt = Result.Nodes.getNodeAs<CompoundStmt>("parent");
104104
const auto *ParentCond = getCondition(Result.Nodes, "parent");
105105
const auto *ParentReturnStmt = Result.Nodes.getNodeAs<ReturnStmt>("parent");
106106

clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp

+48-49
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ AST_MATCHER(clang::VarDecl, isDirectInitialization) {
3535

3636
} // namespace
3737

38-
RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
39-
auto construction_warning =
38+
RewriteRuleWith<std::string> stringviewNullptrCheckImpl() {
39+
auto ConstructionWarning =
4040
cat("constructing basic_string_view from null is undefined; replace with "
4141
"the default constructor");
42-
auto static_cast_warning =
42+
auto StaticCastWarning =
4343
cat("casting to basic_string_view from null is undefined; replace with "
4444
"the empty string");
45-
auto argument_construction_warning =
45+
auto ArgumentConstructionWarning =
4646
cat("passing null as basic_string_view is undefined; replace with the "
4747
"empty string");
48-
auto assignment_warning =
48+
auto AssignmentWarning =
4949
cat("assignment to basic_string_view from null is undefined; replace "
5050
"with the default constructor");
51-
auto relative_comparison_warning =
51+
auto RelativeComparisonWarning =
5252
cat("comparing basic_string_view to null is undefined; replace with the "
5353
"empty string");
54-
auto equality_comparison_warning =
54+
auto EqualityComparisonWarning =
5555
cat("comparing basic_string_view to null is undefined; replace with the "
5656
"emptiness query");
5757

@@ -84,7 +84,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
8484
auto HandleTemporaryCXXFunctionalCastExpr =
8585
makeRule(cxxFunctionalCastExpr(hasSourceExpression(
8686
BasicStringViewConstructingFromNullExpr)),
87-
remove(node("null_arg_expr")), construction_warning);
87+
remove(node("null_arg_expr")), ConstructionWarning);
8888

8989
// `std::string_view{null_arg_expr}` and `(std::string_view){null_arg_expr}`
9090
auto HandleTemporaryCXXTemporaryObjectExprAndCompoundLiteralExpr = makeRule(
@@ -93,28 +93,28 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
9393
hasAnyArgument(/* `hasArgument` would skip over parens */ anyOf(
9494
NullLiteral, NullInitList, EmptyInitList)),
9595
has(expr().bind("null_arg_expr")))),
96-
remove(node("null_arg_expr")), construction_warning);
96+
remove(node("null_arg_expr")), ConstructionWarning);
9797

9898
// `(std::string_view) null_arg_expr`
99-
auto HandleTemporaryCStyleCastExpr = makeRule(
100-
cStyleCastExpr(
101-
hasSourceExpression(BasicStringViewConstructingFromNullExpr)),
102-
changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
99+
auto HandleTemporaryCStyleCastExpr =
100+
makeRule(cStyleCastExpr(hasSourceExpression(
101+
BasicStringViewConstructingFromNullExpr)),
102+
changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
103103

104104
// `static_cast<std::string_view>(null_arg_expr)`
105-
auto HandleTemporaryCXXStaticCastExpr = makeRule(
106-
cxxStaticCastExpr(
107-
hasSourceExpression(BasicStringViewConstructingFromNullExpr)),
108-
changeTo(node("null_arg_expr"), cat("\"\"")), static_cast_warning);
105+
auto HandleTemporaryCXXStaticCastExpr =
106+
makeRule(cxxStaticCastExpr(hasSourceExpression(
107+
BasicStringViewConstructingFromNullExpr)),
108+
changeTo(node("null_arg_expr"), cat("\"\"")), StaticCastWarning);
109109

110110
// `std::string_view sv = null_arg_expr;`
111-
auto HandleStackCopyInitialization = makeRule(
112-
varDecl(HasBasicStringViewType,
113-
hasInitializer(ignoringImpCasts(
114-
cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
115-
unless(isListInitialization())))),
116-
unless(isDirectInitialization())),
117-
changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
111+
auto HandleStackCopyInitialization =
112+
makeRule(varDecl(HasBasicStringViewType,
113+
hasInitializer(ignoringImpCasts(cxxConstructExpr(
114+
BasicStringViewConstructingFromNullExpr,
115+
unless(isListInitialization())))),
116+
unless(isDirectInitialization())),
117+
changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
118118

119119
// `std::string_view sv = {null_arg_expr};`
120120
auto HandleStackCopyListInitialization =
@@ -123,7 +123,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
123123
BasicStringViewConstructingFromNullExpr,
124124
isListInitialization())),
125125
unless(isDirectInitialization())),
126-
remove(node("null_arg_expr")), construction_warning);
126+
remove(node("null_arg_expr")), ConstructionWarning);
127127

128128
// `std::string_view sv(null_arg_expr);`
129129
auto HandleStackDirectInitialization =
@@ -134,7 +134,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
134134
isDirectInitialization())
135135
.bind("var_decl"),
136136
changeTo(node("construct_expr"), cat(name("var_decl"))),
137-
construction_warning);
137+
ConstructionWarning);
138138

139139
// `std::string_view sv{null_arg_expr};`
140140
auto HandleStackDirectListInitialization =
@@ -143,15 +143,15 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
143143
BasicStringViewConstructingFromNullExpr,
144144
isListInitialization())),
145145
isDirectInitialization()),
146-
remove(node("null_arg_expr")), construction_warning);
146+
remove(node("null_arg_expr")), ConstructionWarning);
147147

148148
// `struct S { std::string_view sv = null_arg_expr; };`
149149
auto HandleFieldInClassCopyInitialization = makeRule(
150150
fieldDecl(HasBasicStringViewType,
151151
hasInClassInitializer(ignoringImpCasts(
152152
cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
153153
unless(isListInitialization()))))),
154-
changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
154+
changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
155155

156156
// `struct S { std::string_view sv = {null_arg_expr}; };` and
157157
// `struct S { std::string_view sv{null_arg_expr}; };`
@@ -160,76 +160,75 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
160160
hasInClassInitializer(ignoringImpCasts(
161161
cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
162162
isListInitialization())))),
163-
remove(node("null_arg_expr")), construction_warning);
163+
remove(node("null_arg_expr")), ConstructionWarning);
164164

165165
// `class C { std::string_view sv; C() : sv(null_arg_expr) {} };`
166166
auto HandleConstructorDirectInitialization =
167167
makeRule(cxxCtorInitializer(forField(fieldDecl(HasBasicStringViewType)),
168168
withInitializer(cxxConstructExpr(
169169
BasicStringViewConstructingFromNullExpr,
170170
unless(isListInitialization())))),
171-
remove(node("null_arg_expr")), construction_warning);
171+
remove(node("null_arg_expr")), ConstructionWarning);
172172

173173
// `class C { std::string_view sv; C() : sv{null_arg_expr} {} };`
174174
auto HandleConstructorDirectListInitialization =
175175
makeRule(cxxCtorInitializer(forField(fieldDecl(HasBasicStringViewType)),
176176
withInitializer(cxxConstructExpr(
177177
BasicStringViewConstructingFromNullExpr,
178178
isListInitialization()))),
179-
remove(node("null_arg_expr")), construction_warning);
179+
remove(node("null_arg_expr")), ConstructionWarning);
180180

181181
// `void f(std::string_view sv = null_arg_expr);`
182-
auto HandleDefaultArgumentCopyInitialization = makeRule(
183-
parmVarDecl(HasBasicStringViewType,
184-
hasInitializer(ignoringImpCasts(
185-
cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
186-
unless(isListInitialization()))))),
187-
changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
182+
auto HandleDefaultArgumentCopyInitialization =
183+
makeRule(parmVarDecl(HasBasicStringViewType,
184+
hasInitializer(ignoringImpCasts(cxxConstructExpr(
185+
BasicStringViewConstructingFromNullExpr,
186+
unless(isListInitialization()))))),
187+
changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
188188

189189
// `void f(std::string_view sv = {null_arg_expr});`
190190
auto HandleDefaultArgumentCopyListInitialization =
191191
makeRule(parmVarDecl(HasBasicStringViewType,
192192
hasInitializer(cxxConstructExpr(
193193
BasicStringViewConstructingFromNullExpr,
194194
isListInitialization()))),
195-
remove(node("null_arg_expr")), construction_warning);
195+
remove(node("null_arg_expr")), ConstructionWarning);
196196

197197
// `new std::string_view(null_arg_expr)`
198198
auto HandleHeapDirectInitialization = makeRule(
199199
cxxNewExpr(has(cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
200200
unless(isListInitialization()))),
201201
unless(isArray()), unless(hasAnyPlacementArg(anything()))),
202-
remove(node("null_arg_expr")), construction_warning);
202+
remove(node("null_arg_expr")), ConstructionWarning);
203203

204204
// `new std::string_view{null_arg_expr}`
205205
auto HandleHeapDirectListInitialization = makeRule(
206206
cxxNewExpr(has(cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
207207
isListInitialization())),
208208
unless(isArray()), unless(hasAnyPlacementArg(anything()))),
209-
remove(node("null_arg_expr")), construction_warning);
209+
remove(node("null_arg_expr")), ConstructionWarning);
210210

211211
// `function(null_arg_expr)`
212212
auto HandleFunctionArgumentInitialization =
213213
makeRule(callExpr(hasAnyArgument(ignoringImpCasts(
214214
BasicStringViewConstructingFromNullExpr)),
215215
unless(cxxOperatorCallExpr())),
216216
changeTo(node("construct_expr"), cat("\"\"")),
217-
argument_construction_warning);
217+
ArgumentConstructionWarning);
218218

219219
// `sv = null_arg_expr`
220220
auto HandleAssignment = makeRule(
221221
cxxOperatorCallExpr(hasOverloadedOperatorName("="),
222222
hasRHS(materializeTemporaryExpr(
223223
has(BasicStringViewConstructingFromNullExpr)))),
224-
changeTo(node("construct_expr"), cat("{}")), assignment_warning);
224+
changeTo(node("construct_expr"), cat("{}")), AssignmentWarning);
225225

226226
// `sv < null_arg_expr`
227227
auto HandleRelativeComparison = makeRule(
228228
cxxOperatorCallExpr(hasAnyOverloadedOperatorName("<", "<=", ">", ">="),
229229
hasEitherOperand(ignoringImpCasts(
230230
BasicStringViewConstructingFromNullExpr))),
231-
changeTo(node("construct_expr"), cat("\"\"")),
232-
relative_comparison_warning);
231+
changeTo(node("construct_expr"), cat("\"\"")), RelativeComparisonWarning);
233232

234233
// `sv == null_arg_expr`
235234
auto HandleEmptyEqualityComparison = makeRule(
@@ -240,7 +239,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
240239
expr().bind("instance"))))
241240
.bind("root"),
242241
changeTo(node("root"), cat(access("instance", cat("empty")), "()")),
243-
equality_comparison_warning);
242+
EqualityComparisonWarning);
244243

245244
// `sv != null_arg_expr`
246245
auto HandleNonEmptyEqualityComparison = makeRule(
@@ -251,13 +250,13 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
251250
expr().bind("instance"))))
252251
.bind("root"),
253252
changeTo(node("root"), cat("!", access("instance", cat("empty")), "()")),
254-
equality_comparison_warning);
253+
EqualityComparisonWarning);
255254

256255
// `return null_arg_expr;`
257256
auto HandleReturnStatement = makeRule(
258257
returnStmt(hasReturnValue(
259258
ignoringImpCasts(BasicStringViewConstructingFromNullExpr))),
260-
changeTo(node("construct_expr"), cat("{}")), construction_warning);
259+
changeTo(node("construct_expr"), cat("{}")), ConstructionWarning);
261260

262261
// `T(null_arg_expr)`
263262
auto HandleConstructorInvocation =
@@ -267,7 +266,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
267266
BasicStringViewConstructingFromNullExpr)),
268267
unless(HasBasicStringViewType)),
269268
changeTo(node("construct_expr"), cat("\"\"")),
270-
argument_construction_warning);
269+
ArgumentConstructionWarning);
271270

272271
return applyFirst(
273272
{HandleTemporaryCXXFunctionalCastExpr,
@@ -297,7 +296,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
297296

298297
StringviewNullptrCheck::StringviewNullptrCheck(StringRef Name,
299298
ClangTidyContext *Context)
300-
: utils::TransformerClangTidyCheck(StringviewNullptrCheckImpl(), Name,
299+
: utils::TransformerClangTidyCheck(stringviewNullptrCheckImpl(), Name,
301300
Context) {}
302301

303302
} // namespace clang::tidy::bugprone

clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ AST_MATCHER_P2(RecordDecl, fieldCountOfKindIsOne,
5252
if (InnerMatcher.matches(*Field, Finder, &TempBuilder)) {
5353
if (FirstMatch) {
5454
return false;
55-
} else {
56-
FirstMatch = Field;
5755
}
56+
FirstMatch = Field;
5857
}
5958
}
6059

@@ -112,11 +111,11 @@ void TaggedUnionMemberCountCheck::registerMatchers(MatchFinder *Finder) {
112111
auto EnumField = fieldDecl(hasType(
113112
qualType(hasCanonicalType(enumType(hasDeclaration(enumDecl()))))));
114113

115-
auto hasOneUnionField = fieldCountOfKindIsOne(UnionField, UnionMatchBindName);
116-
auto hasOneEnumField = fieldCountOfKindIsOne(EnumField, TagMatchBindName);
114+
auto HasOneUnionField = fieldCountOfKindIsOne(UnionField, UnionMatchBindName);
115+
auto HasOneEnumField = fieldCountOfKindIsOne(EnumField, TagMatchBindName);
117116

118-
Finder->addMatcher(recordDecl(anyOf(isStruct(), isClass()), hasOneUnionField,
119-
hasOneEnumField, unless(isImplicit()))
117+
Finder->addMatcher(recordDecl(anyOf(isStruct(), isClass()), HasOneUnionField,
118+
HasOneEnumField, unless(isImplicit()))
120119
.bind(RootMatchBindName),
121120
this);
122121
}

clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace {
1818
AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
1919
const ast_matchers::internal::VariadicDynCastAllOfMatcher<Decl,
2020
FileScopeAsmDecl>
21-
fileScopeAsmDecl;
21+
fileScopeAsmDecl; // NOLINT(readability-identifier-*) preserve clang style
2222
} // namespace
2323

2424
void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ static llvm::SmallString<64U> skeleton(StringRef Name) {
6666
}
6767

6868
StringRef Key(Prev, Curr - Prev);
69-
auto Where = llvm::lower_bound(ConfusableEntries, CodePoint,
70-
[](decltype(ConfusableEntries[0]) x,
71-
UTF32 y) { return x.codepoint < y; });
69+
auto *Where = llvm::lower_bound(ConfusableEntries, CodePoint,
70+
[](decltype(ConfusableEntries[0]) X,
71+
UTF32 Y) { return X.codepoint < Y; });
7272
if (Where == std::end(ConfusableEntries) || CodePoint != Where->codepoint) {
7373
Skeleton.append(Prev, Curr);
7474
} else {

0 commit comments

Comments
 (0)