Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions clang-tools-extra/clang-tidy/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
InheritParentConfig: true
Checks: [
bugprone-*,
-bugprone-assignment-in-if-condition,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-narrowing-conversions,
-bugprone-suspicious-stringview-data-usage,
-bugprone-unchecked-optional-access,
-bugprone-unused-return-value,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-pass-by-value,
-modernize-use-auto,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
performance-*,
-performance-enum-size,
-performance-move-const-arg,
-performance-no-int-to-ptr,
-performance-type-promotion-in-math-fn,
-performance-unnecessary-value-param,
readability-*,
-readability-avoid-nested-conditional-operator,
-readability-avoid-return-with-void-value,
-readability-braces-around-statements,
-readability-container-contains,
-readability-convert-member-functions-to-static,
-readability-else-after-return, # enabled via 'llvm-else-after-return'
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-isolate-declaration,
-readability-magic-numbers,
-readability-named-parameter,
-readability-qualified-auto, # enabled via 'llvm-qualified-auto'
-readability-redundant-declaration,
-readability-simplify-boolean-expr,
-readability-static-definition-in-anonymous-namespace,
-readability-suspicious-call-argument,
-readability-use-anyofallof
]
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/boost/UseRangesCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UseRangesCheck : public utils::UseRangesCheck {
public:
UseRangesCheck(StringRef Name, ClangTidyContext *Context);

void storeOptions(ClangTidyOptions::OptionMap &Options) override;
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

ReplacerMap getReplacerMap() const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
std::string ArgNameLowerStr = ArgName.lower();
StringRef ArgNameLower = ArgNameLowerStr;
// The threshold is arbitrary.
unsigned UpperBound = (ArgName.size() + 2) / 3 + 1;
unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
unsigned ThisED = ArgNameLower.edit_distance(
Params[ArgIndex]->getIdentifier()->getName().lower(),
/*AllowReplacements=*/true, UpperBound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,10 @@ void CrtpConstructorAccessibilityCheck::check(
<< HintFriend;
}

auto WithFriendHintIfNeeded =
[&](const DiagnosticBuilder &Diag,
bool NeedsFriend) -> const DiagnosticBuilder & {
auto WithFriendHintIfNeeded = [&](const DiagnosticBuilder &Diag,
bool NeedsFriend) {
if (NeedsFriend)
Diag << HintFriend;

return Diag;
};

if (!CRTPDeclaration->hasUserDeclaredConstructor()) {
Expand Down
6 changes: 2 additions & 4 deletions clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ using namespace clang::ast_matchers;
using clang::ast_matchers::internal::Matcher;
using clang::tidy::utils::hasPtrOrReferenceInFunc;

namespace clang {
namespace tidy::bugprone {
namespace clang::tidy::bugprone {

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

} // namespace tidy::bugprone
} // namespace clang
} // namespace clang::tidy::bugprone
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ unsigned MacroRepeatedPPCallbacks::countArgumentExpansions(
// Count argument.
if (TII == Arg) {
Current++;
if (Current > Max)
Max = Current;
Max = std::max(Max, Current);
}
}
return Max;
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,16 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
<< E->getSourceRange();
} else if (Result.Nodes.getNodeAs<Stmt>("loop-expr")) {
auto *SizeofArgTy = Result.Nodes.getNodeAs<Type>("sizeof-arg-type");
if (const auto member = dyn_cast<MemberPointerType>(SizeofArgTy))
SizeofArgTy = member->getPointeeType().getTypePtr();
if (const auto *Member = dyn_cast<MemberPointerType>(SizeofArgTy))
SizeofArgTy = Member->getPointeeType().getTypePtr();

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

if (const auto type = dyn_cast<ArrayType>(SizeofArgTy)) {
if (const auto *Type = dyn_cast<ArrayType>(SizeofArgTy)) {
// check if the array element size is larger than one. If true,
// the size of the array is higher than the number of elements
CharUnits sSize = Ctx.getTypeSizeInChars(type->getElementType());
if (!sSize.isOne()) {
CharUnits SSize = Ctx.getTypeSizeInChars(Type->getElementType());
if (!SSize.isOne()) {
diag(SzOfExpr->getBeginLoc(),
"suspicious usage of 'sizeof' in the loop")
<< SzOfExpr->getSourceRange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void UnsafeFunctionsCheck::registerMatchers(MatchFinder *Finder) {
FunctionNames.reserve(CustomFunctions.size());

for (const auto &Entry : CustomFunctions)
FunctionNames.push_back(Entry.Name);
FunctionNames.emplace_back(Entry.Name);

auto CustomFunctionsMatcher = matchers::matchesAnyListedName(FunctionNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {

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

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,9 @@ static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp,
if (Rsr.getBegin().isMacroID()) {
// Both sides are macros so they are same macro or literal
const llvm::StringRef L = Lexer::getSourceText(
CharSourceRange::getTokenRange(Lsr), SM, Context->getLangOpts(), 0);
CharSourceRange::getTokenRange(Lsr), SM, Context->getLangOpts());
const llvm::StringRef R = Lexer::getSourceText(
CharSourceRange::getTokenRange(Rsr), SM, Context->getLangOpts(), 0);
CharSourceRange::getTokenRange(Rsr), SM, Context->getLangOpts());
return areStringsSameIgnoreSpaces(L, R);
}
// Left is macro but right is not so they are not same macro or literal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ matchTrailingTemplateParam(const FunctionTemplateDecl *FunctionTemplate) {

const TemplateParameterList *TemplateParams =
FunctionTemplate->getTemplateParameters();
if (TemplateParams->size() == 0)
if (TemplateParams->empty())
return {};

const NamedDecl *LastParam =
Expand Down Expand Up @@ -419,7 +419,7 @@ handleTrailingTemplateType(const FunctionTemplateDecl *FunctionTemplate,
SourceRange RemovalRange;
const TemplateParameterList *TemplateParams =
FunctionTemplate->getTemplateParameters();
if (!TemplateParams || TemplateParams->size() == 0)
if (!TemplateParams || TemplateParams->empty())
return {};

if (TemplateParams->size() == 1) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UseRangesCheck : public utils::UseRangesCheck {
public:
UseRangesCheck(StringRef CheckName, ClangTidyContext *Context);

void storeOptions(ClangTidyOptions::OptionMap &Options) override;
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

ReplacerMap getReplacerMap() const override;

Expand Down
7 changes: 3 additions & 4 deletions clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ getTemplateLockGuardTypeLoc(const TypeSourceInfo *SourceInfo) {
static SourceRange getLockGuardRange(const TypeSourceInfo *SourceInfo) {
const TypeLoc LockGuardTypeLoc = SourceInfo->getTypeLoc();

return SourceRange(LockGuardTypeLoc.getBeginLoc(),
LockGuardTypeLoc.getEndLoc());
return {LockGuardTypeLoc.getBeginLoc(), LockGuardTypeLoc.getEndLoc()};
}

// Find the exact source range of the 'lock_guard' name token
Expand All @@ -115,8 +114,8 @@ static SourceRange getLockGuardNameRange(const TypeSourceInfo *SourceInfo) {
if (!TemplateLoc)
return {};

return SourceRange(TemplateLoc.getTemplateNameLoc(),
TemplateLoc.getLAngleLoc().getLocWithOffset(-1));
return {TemplateLoc.getTemplateNameLoc(),
TemplateLoc.getLAngleLoc().getLocWithOffset(-1)};
}

const static StringRef UseScopedLockMessage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
areDiagsSelfContained()),
MaybeHeaderToInclude(Options.get("FormatHeader")) {
if (StrFormatLikeFunctions.empty())
StrFormatLikeFunctions.push_back("absl::StrFormat");
StrFormatLikeFunctions.emplace_back("absl::StrFormat");

if (!MaybeHeaderToInclude && ReplacementFormatFunction == "std::format")
MaybeHeaderToInclude = "<format>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
void PropertyDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedDecl =
Result.Nodes.getNodeAs<ObjCPropertyDecl>("property");
assert(MatchedDecl->getName().size() > 0);
assert(!MatchedDecl->getName().empty());
auto *DeclContext = MatchedDecl->getDeclContext();
auto *CategoryDecl = llvm::dyn_cast<ObjCCategoryDecl>(DeclContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
} UsageOfThis;

// TraverseStmt does not modify its argument.
UsageOfThis.TraverseStmt(const_cast<Stmt *>(Node.getBody()));
UsageOfThis.TraverseStmt(Node.getBody());

return UsageOfThis.Used;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ AST_MATCHER(CXXMethodDecl, usesThisAsConst) {
FindUsageOfThis UsageOfThis(Finder->getASTContext());

// TraverseStmt does not modify its argument.
UsageOfThis.TraverseStmt(const_cast<Stmt *>(Node.getBody()));
UsageOfThis.TraverseStmt(Node.getBody());

return UsageOfThis.Usage == Const;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static bool applyJaroWinklerHeuristic(StringRef Arg, StringRef Param,
SmallVector<int, SmallVectorSize> ArgFlags(ArgLen);
SmallVector<int, SmallVectorSize> ParamFlags(ParamLen);
std::ptrdiff_t Range =
std::max(std::ptrdiff_t{0}, std::max(ArgLen, ParamLen) / 2 - 1);
std::max(std::ptrdiff_t{0}, (std::max(ArgLen, ParamLen) / 2) - 1);

// Calculate matching characters.
for (std::ptrdiff_t I = 0; I < ParamLen; ++I)
Expand Down Expand Up @@ -260,7 +260,7 @@ static bool applyJaroWinklerHeuristic(StringRef Arg, StringRef Param,
// Calculate common string prefix up to 4 chars.
L = 0;
for (std::ptrdiff_t I = 0;
I < std::min(std::min(ArgLen, ParamLen), std::ptrdiff_t{4}); ++I)
I < std::min({ArgLen, ParamLen, std::ptrdiff_t{4}}); ++I)
if (tolower(Arg[I]) == tolower(Param[I]))
++L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AggregateDesignatorNames {
}
}
// Returns false if the type was not an aggregate.
operator bool() { return Valid; }
operator bool() const { return Valid; }
// Advance to the next element in the aggregate.
void next() {
if (IsArray)
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ class HeaderGuardPPCallbacks : public PPCallbacks {

Check->diag(StartLoc, "header is missing header guard")
<< FixItHint::CreateInsertion(
StartLoc, "#ifndef " + CPPVar + "\n#define " + CPPVar + "\n\n")
StartLoc,
(Twine("#ifndef ") + CPPVar + "\n#define " + CPPVar + "\n\n")
.str())
<< FixItHint::CreateInsertion(
SM.getLocForEndOfFile(FID),
Check->shouldSuggestEndifComment(FileName)
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ template <>
struct DenseMapInfo<clang::tidy::RenamerClangTidyCheck::NamingCheckId> {
using NamingCheckId = clang::tidy::RenamerClangTidyCheck::NamingCheckId;

static inline NamingCheckId getEmptyKey() {
static NamingCheckId getEmptyKey() {
return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(), "EMPTY"};
}

static inline NamingCheckId getTombstoneKey() {
static NamingCheckId getTombstoneKey() {
return {DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
"TOMBSTONE"};
}
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static std::string getFullPrefix(ArrayRef<UseRangesCheck::Indexes> Signature) {
llvm::raw_string_ostream OS(Output);
for (const UseRangesCheck::Indexes &Item : Signature)
OS << Item.BeginArg << ":" << Item.EndArg << ":"
<< (Item.ReplaceArg == Item.First ? '0' : '1');
<< (Item.ReplaceArg == UseRangesCheck::Indexes::First ? '0' : '1');
return Output;
}

Expand Down Expand Up @@ -194,7 +194,7 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call,
void UseRangesCheck::check(const MatchFinder::MatchResult &Result) {
Replacer *Replacer = nullptr;
const FunctionDecl *Function = nullptr;
for (auto [Node, Value] : Result.Nodes.getMap()) {
for (const auto &[Node, Value] : Result.Nodes.getMap()) {
StringRef NodeStr(Node);
if (!NodeStr.consume_front(FuncDecl))
continue;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/utils/UseRangesCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class UseRangesCheck : public ClangTidyCheck {
void registerMatchers(ast_matchers::MatchFinder *Finder) final;
void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
void storeOptions(ClangTidyOptions::OptionMap &Options) override;
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
std::optional<TraversalKind> getCheckTraversalKind() const override;

private:
Expand Down