-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy][NFC] fix clang-tidy
warnings in clang-tools-extra/clang-tidy
directory
#136097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Baranov Victor (vbvictor) ChangesMostly stylistic changes to Command run: Patch is 35.39 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/136097.diff 16 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp b/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
index 06f98c76269b5..664ec59997b59 100644
--- a/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
@@ -21,9 +21,9 @@ using namespace ::clang::transformer;
namespace clang::tidy::abseil {
-RewriteRuleWith<std::string> CleanupCtadCheckImpl() {
- auto warning_message = cat("prefer absl::Cleanup's class template argument "
- "deduction pattern in C++17 and higher");
+RewriteRuleWith<std::string> cleanupCtadCheckImpl() {
+ auto WarningMessage = cat("prefer absl::Cleanup's class template argument "
+ "deduction pattern in C++17 and higher");
return makeRule(
declStmt(hasSingleDecl(varDecl(
@@ -34,10 +34,10 @@ RewriteRuleWith<std::string> CleanupCtadCheckImpl() {
.bind("make_cleanup_call")))))),
{changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
changeTo(node("make_cleanup_call"), cat(callArgs("make_cleanup_call")))},
- warning_message);
+ WarningMessage);
}
CleanupCtadCheck::CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
- : utils::TransformerClangTidyCheck(CleanupCtadCheckImpl(), Name, Context) {}
+ : utils::TransformerClangTidyCheck(cleanupCtadCheckImpl(), Name, Context) {}
} // namespace clang::tidy::abseil
diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index a7e25141b3fe2..a544ef0d9dd04 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -250,10 +250,10 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
if (!llvm::all_of(llvm::zip(CompStmt1->body(), CompStmt2->body()),
[&Ctx, IgnoreSideEffects](
- std::tuple<const Stmt *, const Stmt *> stmtPair) {
- const Stmt *stmt0 = std::get<0>(stmtPair);
- const Stmt *stmt1 = std::get<1>(stmtPair);
- return isIdenticalStmt(Ctx, stmt0, stmt1,
+ std::tuple<const Stmt *, const Stmt *> StmtPair) {
+ const Stmt *Stmt0 = std::get<0>(StmtPair);
+ const Stmt *Stmt1 = std::get<1>(StmtPair);
+ return isIdenticalStmt(Ctx, Stmt0, Stmt1,
IgnoreSideEffects);
})) {
return false;
@@ -477,7 +477,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *IS = Result.Nodes.getNodeAs<IfStmt>("ifWithDescendantIf")) {
const Stmt *Then = IS->getThen();
- auto CS = dyn_cast<CompoundStmt>(Then);
+ const auto *CS = dyn_cast<CompoundStmt>(Then);
if (CS && (!CS->body_empty())) {
const auto *InnerIf = dyn_cast<IfStmt>(*CS->body_begin());
if (InnerIf && isIdenticalStmt(Context, IS->getCond(), InnerIf->getCond(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index 27045816a80d3..c066b3e7b19a5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -301,7 +301,7 @@ bool isCXXOnlyStmt(const Stmt *S) {
/// It is unspecified which call is found if multiple calls exist, but the order
/// should be deterministic (depend only on the AST).
Expr *findCallExpr(const CallGraphNode *Caller, const CallGraphNode *Callee) {
- auto FoundCallee = llvm::find_if(
+ const auto *FoundCallee = llvm::find_if(
Caller->callees(), [Callee](const CallGraphNode::CallRecord &Call) {
return Call.Callee == Callee;
});
diff --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
index a1d7b9931e419..7114adfb311bc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
@@ -99,8 +99,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
if (Result.Nodes.getNodeAs<Expr>("parent"))
return;
- const auto PParentStmtExpr = Result.Nodes.getNodeAs<Expr>("stexpr");
- const auto ParentCompStmt = Result.Nodes.getNodeAs<CompoundStmt>("parent");
+ const auto *PParentStmtExpr = Result.Nodes.getNodeAs<Expr>("stexpr");
+ const auto *ParentCompStmt = Result.Nodes.getNodeAs<CompoundStmt>("parent");
const auto *ParentCond = getCondition(Result.Nodes, "parent");
const auto *ParentReturnStmt = Result.Nodes.getNodeAs<ReturnStmt>("parent");
diff --git a/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
index ea50250f829f0..2489de17b740b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
@@ -35,23 +35,23 @@ AST_MATCHER(clang::VarDecl, isDirectInitialization) {
} // namespace
-RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
- auto construction_warning =
+RewriteRuleWith<std::string> stringviewNullptrCheckImpl() {
+ auto ConstructionWarning =
cat("constructing basic_string_view from null is undefined; replace with "
"the default constructor");
- auto static_cast_warning =
+ auto StaticCastWarning =
cat("casting to basic_string_view from null is undefined; replace with "
"the empty string");
- auto argument_construction_warning =
+ auto ArgumentConstructionWarning =
cat("passing null as basic_string_view is undefined; replace with the "
"empty string");
- auto assignment_warning =
+ auto AssignmentWarning =
cat("assignment to basic_string_view from null is undefined; replace "
"with the default constructor");
- auto relative_comparison_warning =
+ auto RelativeComparisonWarning =
cat("comparing basic_string_view to null is undefined; replace with the "
"empty string");
- auto equality_comparison_warning =
+ auto EqualityComparisonWarning =
cat("comparing basic_string_view to null is undefined; replace with the "
"emptiness query");
@@ -84,7 +84,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
auto HandleTemporaryCXXFunctionalCastExpr =
makeRule(cxxFunctionalCastExpr(hasSourceExpression(
BasicStringViewConstructingFromNullExpr)),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `std::string_view{null_arg_expr}` and `(std::string_view){null_arg_expr}`
auto HandleTemporaryCXXTemporaryObjectExprAndCompoundLiteralExpr = makeRule(
@@ -93,28 +93,28 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
hasAnyArgument(/* `hasArgument` would skip over parens */ anyOf(
NullLiteral, NullInitList, EmptyInitList)),
has(expr().bind("null_arg_expr")))),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `(std::string_view) null_arg_expr`
- auto HandleTemporaryCStyleCastExpr = makeRule(
- cStyleCastExpr(
- hasSourceExpression(BasicStringViewConstructingFromNullExpr)),
- changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
+ auto HandleTemporaryCStyleCastExpr =
+ makeRule(cStyleCastExpr(hasSourceExpression(
+ BasicStringViewConstructingFromNullExpr)),
+ changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
// `static_cast<std::string_view>(null_arg_expr)`
- auto HandleTemporaryCXXStaticCastExpr = makeRule(
- cxxStaticCastExpr(
- hasSourceExpression(BasicStringViewConstructingFromNullExpr)),
- changeTo(node("null_arg_expr"), cat("\"\"")), static_cast_warning);
+ auto HandleTemporaryCXXStaticCastExpr =
+ makeRule(cxxStaticCastExpr(hasSourceExpression(
+ BasicStringViewConstructingFromNullExpr)),
+ changeTo(node("null_arg_expr"), cat("\"\"")), StaticCastWarning);
// `std::string_view sv = null_arg_expr;`
- auto HandleStackCopyInitialization = makeRule(
- varDecl(HasBasicStringViewType,
- hasInitializer(ignoringImpCasts(
- cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
- unless(isListInitialization())))),
- unless(isDirectInitialization())),
- changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
+ auto HandleStackCopyInitialization =
+ makeRule(varDecl(HasBasicStringViewType,
+ hasInitializer(ignoringImpCasts(cxxConstructExpr(
+ BasicStringViewConstructingFromNullExpr,
+ unless(isListInitialization())))),
+ unless(isDirectInitialization())),
+ changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
// `std::string_view sv = {null_arg_expr};`
auto HandleStackCopyListInitialization =
@@ -123,7 +123,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
BasicStringViewConstructingFromNullExpr,
isListInitialization())),
unless(isDirectInitialization())),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `std::string_view sv(null_arg_expr);`
auto HandleStackDirectInitialization =
@@ -134,7 +134,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
isDirectInitialization())
.bind("var_decl"),
changeTo(node("construct_expr"), cat(name("var_decl"))),
- construction_warning);
+ ConstructionWarning);
// `std::string_view sv{null_arg_expr};`
auto HandleStackDirectListInitialization =
@@ -143,7 +143,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
BasicStringViewConstructingFromNullExpr,
isListInitialization())),
isDirectInitialization()),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `struct S { std::string_view sv = null_arg_expr; };`
auto HandleFieldInClassCopyInitialization = makeRule(
@@ -151,7 +151,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
hasInClassInitializer(ignoringImpCasts(
cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
unless(isListInitialization()))))),
- changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
+ changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
// `struct S { std::string_view sv = {null_arg_expr}; };` and
// `struct S { std::string_view sv{null_arg_expr}; };`
@@ -160,7 +160,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
hasInClassInitializer(ignoringImpCasts(
cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
isListInitialization())))),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `class C { std::string_view sv; C() : sv(null_arg_expr) {} };`
auto HandleConstructorDirectInitialization =
@@ -168,7 +168,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
withInitializer(cxxConstructExpr(
BasicStringViewConstructingFromNullExpr,
unless(isListInitialization())))),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `class C { std::string_view sv; C() : sv{null_arg_expr} {} };`
auto HandleConstructorDirectListInitialization =
@@ -176,15 +176,15 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
withInitializer(cxxConstructExpr(
BasicStringViewConstructingFromNullExpr,
isListInitialization()))),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `void f(std::string_view sv = null_arg_expr);`
- auto HandleDefaultArgumentCopyInitialization = makeRule(
- parmVarDecl(HasBasicStringViewType,
- hasInitializer(ignoringImpCasts(
- cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
- unless(isListInitialization()))))),
- changeTo(node("null_arg_expr"), cat("{}")), construction_warning);
+ auto HandleDefaultArgumentCopyInitialization =
+ makeRule(parmVarDecl(HasBasicStringViewType,
+ hasInitializer(ignoringImpCasts(cxxConstructExpr(
+ BasicStringViewConstructingFromNullExpr,
+ unless(isListInitialization()))))),
+ changeTo(node("null_arg_expr"), cat("{}")), ConstructionWarning);
// `void f(std::string_view sv = {null_arg_expr});`
auto HandleDefaultArgumentCopyListInitialization =
@@ -192,21 +192,21 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
hasInitializer(cxxConstructExpr(
BasicStringViewConstructingFromNullExpr,
isListInitialization()))),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `new std::string_view(null_arg_expr)`
auto HandleHeapDirectInitialization = makeRule(
cxxNewExpr(has(cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
unless(isListInitialization()))),
unless(isArray()), unless(hasAnyPlacementArg(anything()))),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `new std::string_view{null_arg_expr}`
auto HandleHeapDirectListInitialization = makeRule(
cxxNewExpr(has(cxxConstructExpr(BasicStringViewConstructingFromNullExpr,
isListInitialization())),
unless(isArray()), unless(hasAnyPlacementArg(anything()))),
- remove(node("null_arg_expr")), construction_warning);
+ remove(node("null_arg_expr")), ConstructionWarning);
// `function(null_arg_expr)`
auto HandleFunctionArgumentInitialization =
@@ -214,22 +214,21 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
BasicStringViewConstructingFromNullExpr)),
unless(cxxOperatorCallExpr())),
changeTo(node("construct_expr"), cat("\"\"")),
- argument_construction_warning);
+ ArgumentConstructionWarning);
// `sv = null_arg_expr`
auto HandleAssignment = makeRule(
cxxOperatorCallExpr(hasOverloadedOperatorName("="),
hasRHS(materializeTemporaryExpr(
has(BasicStringViewConstructingFromNullExpr)))),
- changeTo(node("construct_expr"), cat("{}")), assignment_warning);
+ changeTo(node("construct_expr"), cat("{}")), AssignmentWarning);
// `sv < null_arg_expr`
auto HandleRelativeComparison = makeRule(
cxxOperatorCallExpr(hasAnyOverloadedOperatorName("<", "<=", ">", ">="),
hasEitherOperand(ignoringImpCasts(
BasicStringViewConstructingFromNullExpr))),
- changeTo(node("construct_expr"), cat("\"\"")),
- relative_comparison_warning);
+ changeTo(node("construct_expr"), cat("\"\"")), RelativeComparisonWarning);
// `sv == null_arg_expr`
auto HandleEmptyEqualityComparison = makeRule(
@@ -240,7 +239,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
expr().bind("instance"))))
.bind("root"),
changeTo(node("root"), cat(access("instance", cat("empty")), "()")),
- equality_comparison_warning);
+ EqualityComparisonWarning);
// `sv != null_arg_expr`
auto HandleNonEmptyEqualityComparison = makeRule(
@@ -251,13 +250,13 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
expr().bind("instance"))))
.bind("root"),
changeTo(node("root"), cat("!", access("instance", cat("empty")), "()")),
- equality_comparison_warning);
+ EqualityComparisonWarning);
// `return null_arg_expr;`
auto HandleReturnStatement = makeRule(
returnStmt(hasReturnValue(
ignoringImpCasts(BasicStringViewConstructingFromNullExpr))),
- changeTo(node("construct_expr"), cat("{}")), construction_warning);
+ changeTo(node("construct_expr"), cat("{}")), ConstructionWarning);
// `T(null_arg_expr)`
auto HandleConstructorInvocation =
@@ -267,7 +266,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
BasicStringViewConstructingFromNullExpr)),
unless(HasBasicStringViewType)),
changeTo(node("construct_expr"), cat("\"\"")),
- argument_construction_warning);
+ ArgumentConstructionWarning);
return applyFirst(
{HandleTemporaryCXXFunctionalCastExpr,
@@ -297,7 +296,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
StringviewNullptrCheck::StringviewNullptrCheck(StringRef Name,
ClangTidyContext *Context)
- : utils::TransformerClangTidyCheck(StringviewNullptrCheckImpl(), Name,
+ : utils::TransformerClangTidyCheck(stringviewNullptrCheckImpl(), Name,
Context) {}
} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
index db99ef3786e5f..db0ac281ddfcf 100644
--- a/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
@@ -52,9 +52,8 @@ AST_MATCHER_P2(RecordDecl, fieldCountOfKindIsOne,
if (InnerMatcher.matches(*Field, Finder, &TempBuilder)) {
if (FirstMatch) {
return false;
- } else {
- FirstMatch = Field;
}
+ FirstMatch = Field;
}
}
@@ -112,11 +111,11 @@ void TaggedUnionMemberCountCheck::registerMatchers(MatchFinder *Finder) {
auto EnumField = fieldDecl(hasType(
qualType(hasCanonicalType(enumType(hasDeclaration(enumDecl()))))));
- auto hasOneUnionField = fieldCountOfKindIsOne(UnionField, UnionMatchBindName);
- auto hasOneEnumField = fieldCountOfKindIsOne(EnumField, TagMatchBindName);
+ auto HasOneUnionField = fieldCountOfKindIsOne(UnionField, UnionMatchBindName);
+ auto HasOneEnumField = fieldCountOfKindIsOne(EnumField, TagMatchBindName);
- Finder->addMatcher(recordDecl(anyOf(isStruct(), isClass()), hasOneUnionField,
- hasOneEnumField, unless(isImplicit()))
+ Finder->addMatcher(recordDecl(anyOf(isStruct(), isClass()), HasOneUnionField,
+ HasOneEnumField, unless(isImplicit()))
.bind(RootMatchBindName),
this);
}
diff --git a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
index 1dc2463d0fc0a..9f31227d9753b 100644
--- a/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
@...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…ng-tidy` directory (llvm#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`
…ng-tidy` directory (llvm#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`
…ng-tidy` directory (llvm#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`
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