Skip to content

Commit d7a1754

Browse files
authored
[clang-tidy][NFC] add '.clang-tidy' config for clang-tidy project (#147793)
Added `.clang-tidy` config as discussed in [RFC](https://discourse.llvm.org/t/rfc-create-hardened-clang-tidy-config-for-clang-tidy-directory/87247). Added `bugprone`, `readability`, `modernize`, `performance` checks that didn't create many warnings. Fixed minor warnings to make `/clang-tidy` directory complaint with `clang-tidy-20`. Disabled checks will be enabled in future PRs after fixing their warnings.
1 parent a89021b commit d7a1754

23 files changed

+78
-42
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
InheritParentConfig: true
2+
Checks: >
3+
bugprone-*,
4+
-bugprone-assignment-in-if-condition,
5+
-bugprone-branch-clone,
6+
-bugprone-easily-swappable-parameters,
7+
-bugprone-narrowing-conversions,
8+
-bugprone-suspicious-stringview-data-usage,
9+
-bugprone-unchecked-optional-access,
10+
-bugprone-unused-return-value,
11+
modernize-*,
12+
-modernize-avoid-c-arrays,
13+
-modernize-pass-by-value,
14+
-modernize-use-auto,
15+
-modernize-use-nodiscard,
16+
-modernize-use-trailing-return-type,
17+
performance-*,
18+
-performance-enum-size,
19+
-performance-move-const-arg,
20+
-performance-no-int-to-ptr,
21+
-performance-type-promotion-in-math-fn,
22+
-performance-unnecessary-value-param,
23+
readability-*,
24+
-readability-avoid-nested-conditional-operator,
25+
-readability-avoid-return-with-void-value,
26+
-readability-braces-around-statements,
27+
-readability-container-contains,
28+
-readability-convert-member-functions-to-static,
29+
-readability-else-after-return,
30+
-readability-function-cognitive-complexity,
31+
-readability-identifier-length,
32+
-readability-implicit-bool-conversion,
33+
-readability-isolate-declaration,
34+
-readability-magic-numbers,
35+
-readability-named-parameter,
36+
-readability-qualified-auto,
37+
-readability-redundant-declaration,
38+
-readability-simplify-boolean-expr,
39+
-readability-static-definition-in-anonymous-namespace,
40+
-readability-suspicious-call-argument,
41+
-readability-use-anyofallof

clang-tools-extra/clang-tidy/boost/UseRangesCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UseRangesCheck : public utils::UseRangesCheck {
2222
public:
2323
UseRangesCheck(StringRef Name, ClangTidyContext *Context);
2424

25-
void storeOptions(ClangTidyOptions::OptionMap &Options) override;
25+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2626

2727
ReplacerMap getReplacerMap() const override;
2828

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
145145
std::string ArgNameLowerStr = ArgName.lower();
146146
StringRef ArgNameLower = ArgNameLowerStr;
147147
// The threshold is arbitrary.
148-
unsigned UpperBound = (ArgName.size() + 2) / 3 + 1;
148+
unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
149149
unsigned ThisED = ArgNameLower.edit_distance(
150150
Params[ArgIndex]->getIdentifier()->getName().lower(),
151151
/*AllowReplacements=*/true, UpperBound);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,10 @@ void CrtpConstructorAccessibilityCheck::check(
129129
<< HintFriend;
130130
}
131131

132-
auto WithFriendHintIfNeeded =
133-
[&](const DiagnosticBuilder &Diag,
134-
bool NeedsFriend) -> const DiagnosticBuilder & {
132+
auto WithFriendHintIfNeeded = [&](const DiagnosticBuilder &Diag,
133+
bool NeedsFriend) {
135134
if (NeedsFriend)
136135
Diag << HintFriend;
137-
138-
return Diag;
139136
};
140137

141138
if (!CRTPDeclaration->hasUserDeclaredConstructor()) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ using namespace clang::ast_matchers;
1818
using clang::ast_matchers::internal::Matcher;
1919
using clang::tidy::utils::hasPtrOrReferenceInFunc;
2020

21-
namespace clang {
22-
namespace tidy::bugprone {
21+
namespace clang::tidy::bugprone {
2322

2423
namespace {
2524
/// matches a Decl if it has a "no return" attribute of any kind
@@ -327,5 +326,4 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
327326
}
328327
}
329328

330-
} // namespace tidy::bugprone
331-
} // namespace clang
329+
} // namespace clang::tidy::bugprone

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ unsigned MacroRepeatedPPCallbacks::countArgumentExpansions(
153153
// Count argument.
154154
if (TII == Arg) {
155155
Current++;
156-
if (Current > Max)
157-
Max = Current;
156+
Max = std::max(Max, Current);
158157
}
159158
}
160159
return Max;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,16 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
370370
<< E->getSourceRange();
371371
} else if (Result.Nodes.getNodeAs<Stmt>("loop-expr")) {
372372
auto *SizeofArgTy = Result.Nodes.getNodeAs<Type>("sizeof-arg-type");
373-
if (const auto member = dyn_cast<MemberPointerType>(SizeofArgTy))
374-
SizeofArgTy = member->getPointeeType().getTypePtr();
373+
if (const auto *Member = dyn_cast<MemberPointerType>(SizeofArgTy))
374+
SizeofArgTy = Member->getPointeeType().getTypePtr();
375375

376376
const auto *SzOfExpr = Result.Nodes.getNodeAs<Expr>("sizeof-expr");
377377

378-
if (const auto type = dyn_cast<ArrayType>(SizeofArgTy)) {
378+
if (const auto *Type = dyn_cast<ArrayType>(SizeofArgTy)) {
379379
// check if the array element size is larger than one. If true,
380380
// the size of the array is higher than the number of elements
381-
CharUnits sSize = Ctx.getTypeSizeInChars(type->getElementType());
382-
if (!sSize.isOne()) {
381+
CharUnits SSize = Ctx.getTypeSizeInChars(Type->getElementType());
382+
if (!SSize.isOne()) {
383383
diag(SzOfExpr->getBeginLoc(),
384384
"suspicious usage of 'sizeof' in the loop")
385385
<< SzOfExpr->getSourceRange();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void UnsafeFunctionsCheck::registerMatchers(MatchFinder *Finder) {
248248
FunctionNames.reserve(CustomFunctions.size());
249249

250250
for (const auto &Entry : CustomFunctions)
251-
FunctionNames.push_back(Entry.Name);
251+
FunctionNames.emplace_back(Entry.Name);
252252

253253
auto CustomFunctionsMatcher = matchers::matchesAnyListedName(FunctionNames);
254254

clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
8181

8282
AST_MATCHER(VarDecl, hasIdentifier) {
8383
const IdentifierInfo *ID = Node.getIdentifier();
84-
return ID != NULL && !ID->isPlaceholder();
84+
return ID != nullptr && !ID->isPlaceholder();
8585
}
8686

8787
} // namespace

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,9 @@ static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp,
910910
if (Rsr.getBegin().isMacroID()) {
911911
// Both sides are macros so they are same macro or literal
912912
const llvm::StringRef L = Lexer::getSourceText(
913-
CharSourceRange::getTokenRange(Lsr), SM, Context->getLangOpts(), 0);
913+
CharSourceRange::getTokenRange(Lsr), SM, Context->getLangOpts());
914914
const llvm::StringRef R = Lexer::getSourceText(
915-
CharSourceRange::getTokenRange(Rsr), SM, Context->getLangOpts(), 0);
915+
CharSourceRange::getTokenRange(Rsr), SM, Context->getLangOpts());
916916
return areStringsSameIgnoreSpaces(L, R);
917917
}
918918
// Left is macro but right is not so they are not same macro or literal

0 commit comments

Comments
 (0)