[clang-tidy][NFC] run clang-format over clang-tidy checks and tool code. (#143324)
This commit is contained in:
@@ -419,8 +419,8 @@ ClangTidyASTConsumerFactory::createASTConsumer(
|
||||
|
||||
std::unique_ptr<ClangTidyProfiling> Profiling;
|
||||
if (Context.getEnableProfiling()) {
|
||||
Profiling = std::make_unique<ClangTidyProfiling>(
|
||||
Context.getProfileStorageParams());
|
||||
Profiling =
|
||||
std::make_unique<ClangTidyProfiling>(Context.getProfileStorageParams());
|
||||
FinderOptions.CheckProfiling.emplace(Profiling->Records);
|
||||
}
|
||||
|
||||
@@ -432,8 +432,8 @@ ClangTidyASTConsumerFactory::createASTConsumer(
|
||||
|
||||
if (Context.canEnableModuleHeadersParsing() &&
|
||||
Context.getLangOpts().Modules && OverlayFS != nullptr) {
|
||||
auto ModuleExpander = std::make_unique<ExpandModularHeadersPPCallbacks>(
|
||||
&Compiler, OverlayFS);
|
||||
auto ModuleExpander =
|
||||
std::make_unique<ExpandModularHeadersPPCallbacks>(&Compiler, OverlayFS);
|
||||
ModuleExpanderPP = ModuleExpander->getPreprocessor();
|
||||
PP->addPPCallbacks(std::move(ModuleExpander));
|
||||
}
|
||||
|
||||
@@ -530,7 +530,6 @@ void ClangTidyCheck::OptionsView::store<bool>(
|
||||
ClangTidyOptions::OptionMap &Options, StringRef LocalName,
|
||||
bool Value) const;
|
||||
|
||||
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
||||
|
||||
|
||||
@@ -217,8 +217,7 @@ public:
|
||||
using DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string>;
|
||||
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID,
|
||||
SourceLocation Loc) {
|
||||
return {
|
||||
static_cast<DiagnosticIDs::Level>(
|
||||
return {static_cast<DiagnosticIDs::Level>(
|
||||
DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)),
|
||||
std::string(
|
||||
DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID))};
|
||||
|
||||
@@ -70,7 +70,8 @@ struct NOptionMap {
|
||||
NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
|
||||
Options.reserve(OptionMap.size());
|
||||
for (const auto &KeyValue : OptionMap)
|
||||
Options.emplace_back(std::string(KeyValue.getKey()), KeyValue.getValue().Value);
|
||||
Options.emplace_back(std::string(KeyValue.getKey()),
|
||||
KeyValue.getValue().Value);
|
||||
}
|
||||
ClangTidyOptions::OptionMap denormalize(IO &) {
|
||||
ClangTidyOptions::OptionMap Map;
|
||||
|
||||
@@ -204,7 +204,9 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
|
||||
protected:
|
||||
// A pair of configuration file base name and a function parsing
|
||||
// configuration from text in the corresponding format.
|
||||
using ConfigFileHandler = std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions> (llvm::MemoryBufferRef)>>;
|
||||
using ConfigFileHandler =
|
||||
std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
|
||||
llvm::MemoryBufferRef)>>;
|
||||
|
||||
/// Configuration file handlers listed in the order of priority.
|
||||
///
|
||||
|
||||
@@ -49,8 +49,8 @@ public:
|
||||
FilesToRecord.erase(File);
|
||||
}
|
||||
|
||||
/// Makes sure we have contents for all the files we were interested in. Ideally
|
||||
/// `FilesToRecord` should be empty.
|
||||
/// Makes sure we have contents for all the files we were interested in.
|
||||
/// Ideally `FilesToRecord` should be empty.
|
||||
void checkAllFilesRecorded() {
|
||||
LLVM_DEBUG({
|
||||
for (auto FileEntry : FilesToRecord)
|
||||
|
||||
@@ -35,10 +35,10 @@ namespace tooling {
|
||||
/// including the contents of the modular headers and all their transitive
|
||||
/// includes.
|
||||
///
|
||||
/// This allows existing tools based on PPCallbacks to retain their functionality
|
||||
/// when running with C++ modules enabled. This only works in the backwards
|
||||
/// compatible modules mode, i.e. when code can still be parsed in non-modular
|
||||
/// way.
|
||||
/// This allows existing tools based on PPCallbacks to retain their
|
||||
/// functionality when running with C++ modules enabled. This only works in the
|
||||
/// backwards compatible modules mode, i.e. when code can still be parsed in
|
||||
/// non-modular way.
|
||||
class ExpandModularHeadersPPCallbacks : public PPCallbacks {
|
||||
public:
|
||||
ExpandModularHeadersPPCallbacks(
|
||||
|
||||
@@ -27,7 +27,8 @@ public:
|
||||
|
||||
} // namespace concurrency
|
||||
|
||||
// Register the ConcurrencyTidyModule using this statically initialized variable.
|
||||
// Register the ConcurrencyTidyModule using this statically initialized
|
||||
// variable.
|
||||
static ClangTidyModuleRegistry::Add<concurrency::ConcurrencyModule>
|
||||
X("concurrency-module", "Adds concurrency checks.");
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
|
||||
namespace clang::tidy::hicpp {
|
||||
|
||||
/// Check for thrown exceptions and enforce they are all derived from std::exception.
|
||||
/// Check for thrown exceptions and enforce they are all derived from
|
||||
/// std::exception.
|
||||
///
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/hicpp/exception-baseclass.html
|
||||
|
||||
@@ -19,8 +19,7 @@ void MustCheckErrsCheck::registerMatchers(MatchFinder *Finder) {
|
||||
"ERR_CAST", "PTR_ERR_OR_ZERO"));
|
||||
auto NonCheckingStmts = stmt(anyOf(compoundStmt(), labelStmt()));
|
||||
Finder->addMatcher(
|
||||
callExpr(callee(ErrFn), hasParent(NonCheckingStmts)).bind("call"),
|
||||
this);
|
||||
callExpr(callee(ErrFn), hasParent(NonCheckingStmts)).bind("call"), this);
|
||||
|
||||
auto ReturnToCheck = returnStmt(hasReturnValue(callExpr(callee(ErrFn))));
|
||||
auto ReturnsErrFn = functionDecl(hasDescendant(ReturnToCheck));
|
||||
|
||||
@@ -15,8 +15,9 @@ namespace clang::tidy::llvm_check {
|
||||
|
||||
/// Looks at conditionals and finds and replaces cases of ``cast<>``, which will
|
||||
/// assert rather than return a null pointer, and ``dyn_cast<>`` where
|
||||
/// the return value is not captured. Additionally, finds and replaces cases that match the
|
||||
/// pattern ``var && isa<X>(var)``, where ``var`` is evaluated twice.
|
||||
/// the return value is not captured. Additionally, finds and replaces cases
|
||||
/// that match the pattern ``var && isa<X>(var)``, where ``var`` is evaluated
|
||||
/// twice.
|
||||
///
|
||||
/// Finds cases like these:
|
||||
/// \code
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace clang::tidy::misc {
|
||||
|
||||
///checks for locations that do not throw by value
|
||||
/// Checks for locations that do not throw by value
|
||||
// or catch by reference.
|
||||
// The check is C++ only. It checks that all throw locations
|
||||
// throw by value and not by pointer. Additionally it
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
namespace clang::tidy::modernize {
|
||||
|
||||
/// This check warns the uses of the deprecated member types of ``std::ios_base``
|
||||
/// and replaces those that have a non-deprecated equivalent.
|
||||
/// This check warns the uses of the deprecated member types of
|
||||
/// ``std::ios_base`` and replaces those that have a non-deprecated equivalent.
|
||||
///
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/deprecated-ios-base-aliases.html
|
||||
|
||||
@@ -688,8 +688,7 @@ bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr(ArraySubscriptExpr *E) {
|
||||
if (!isIndexInSubscriptExpr(E->getIdx(), IndexVar))
|
||||
return VisitorBase::TraverseArraySubscriptExpr(E);
|
||||
|
||||
if ((ContainerExpr &&
|
||||
!areSameExpr(Context, Arr->IgnoreParenImpCasts(),
|
||||
if ((ContainerExpr && !areSameExpr(Context, Arr->IgnoreParenImpCasts(),
|
||||
ContainerExpr->IgnoreParenImpCasts())) ||
|
||||
!arrayMatchesBoundExpr(Context, Arr->IgnoreImpCasts()->getType(),
|
||||
ArrayBoundExpr)) {
|
||||
|
||||
@@ -316,8 +316,7 @@ void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
|
||||
CurrentFile = &Files.back();
|
||||
}
|
||||
|
||||
bool MacroToEnumCallbacks::isInitializer(ArrayRef<Token> MacroTokens)
|
||||
{
|
||||
bool MacroToEnumCallbacks::isInitializer(ArrayRef<Token> MacroTokens) {
|
||||
IntegralLiteralExpressionMatcher Matcher(MacroTokens, LangOpts.C99 == 0);
|
||||
bool Matched = Matcher.match();
|
||||
bool IsC = !LangOpts.CPlusPlus;
|
||||
@@ -328,7 +327,6 @@ bool MacroToEnumCallbacks::isInitializer(ArrayRef<Token> MacroTokens)
|
||||
return Matched;
|
||||
}
|
||||
|
||||
|
||||
// Any defined but rejected macro is scanned for identifiers that
|
||||
// are to be excluded as enums.
|
||||
void MacroToEnumCallbacks::MacroDefined(const Token &MacroNameTok,
|
||||
@@ -517,7 +515,8 @@ void MacroToEnumCallbacks::fixEnumMacro(const MacroList &MacroList) const {
|
||||
void MacroToEnumCheck::registerPPCallbacks(const SourceManager &SM,
|
||||
Preprocessor *PP,
|
||||
Preprocessor *ModuleExpanderPP) {
|
||||
auto Callback = std::make_unique<MacroToEnumCallbacks>(this, getLangOpts(), SM);
|
||||
auto Callback =
|
||||
std::make_unique<MacroToEnumCallbacks>(this, getLangOpts(), SM);
|
||||
PPCallback = Callback.get();
|
||||
PP->addPPCallbacks(std::move(Callback));
|
||||
}
|
||||
|
||||
@@ -361,8 +361,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
|
||||
Diag << FixItHint::CreateRemoval(
|
||||
SourceRange(NewStart, InitRange.getBegin()));
|
||||
Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// New array expression with default/value initialization:
|
||||
// smart_ptr<Foo[]>(new int[5]());
|
||||
// smart_ptr<Foo[]>(new Foo[5]());
|
||||
|
||||
@@ -110,11 +110,11 @@ public:
|
||||
CheckFactories.registerCheck<UseDefaultMemberInitCheck>(
|
||||
"modernize-use-default-member-init");
|
||||
CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
|
||||
CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default");
|
||||
CheckFactories.registerCheck<UseEqualsDefaultCheck>(
|
||||
"modernize-use-equals-default");
|
||||
CheckFactories.registerCheck<UseEqualsDeleteCheck>(
|
||||
"modernize-use-equals-delete");
|
||||
CheckFactories.registerCheck<UseNodiscardCheck>(
|
||||
"modernize-use-nodiscard");
|
||||
CheckFactories.registerCheck<UseNodiscardCheck>("modernize-use-nodiscard");
|
||||
CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept");
|
||||
CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
|
||||
CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
|
||||
|
||||
@@ -141,8 +141,7 @@ void ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
"auto_ptr")
|
||||
return;
|
||||
|
||||
SourceLocation EndLoc =
|
||||
AutoPtrLoc.getLocWithOffset(strlen("auto_ptr") - 1);
|
||||
SourceLocation EndLoc = AutoPtrLoc.getLocWithOffset(strlen("auto_ptr") - 1);
|
||||
diag(AutoPtrLoc, "auto_ptr is deprecated, use unique_ptr instead")
|
||||
<< FixItHint::CreateReplacement(SourceRange(AutoPtrLoc, EndLoc),
|
||||
"unique_ptr");
|
||||
|
||||
@@ -38,8 +38,7 @@ size_t getTypeNameLength(bool RemoveStars, StringRef Text) {
|
||||
else if (C == '>')
|
||||
--TemplateTypenameCntr;
|
||||
const CharType NextChar =
|
||||
isAlphanumeric(C)
|
||||
? Alpha
|
||||
isAlphanumeric(C) ? Alpha
|
||||
: (isWhitespace(C) ||
|
||||
(!RemoveStars && TemplateTypenameCntr == 0 && C == '*'))
|
||||
? Space
|
||||
@@ -444,8 +443,8 @@ void UseAutoCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
replaceIterators(Decl, Result.Context);
|
||||
} else if (const auto *Decl =
|
||||
Result.Nodes.getNodeAs<DeclStmt>(DeclWithNewId)) {
|
||||
replaceExpr(Decl, Result.Context,
|
||||
[](const Expr *Expr) { return Expr->getType(); },
|
||||
replaceExpr(
|
||||
Decl, Result.Context, [](const Expr *Expr) { return Expr->getType(); },
|
||||
"use auto when initializing with new to avoid "
|
||||
"duplicating the type name");
|
||||
} else if (const auto *Decl =
|
||||
|
||||
@@ -98,8 +98,8 @@ auto hasWantedType(llvm::ArrayRef<StringRef> TypeNames) {
|
||||
|
||||
// Matches member call expressions of the named method on the listed container
|
||||
// types.
|
||||
auto cxxMemberCallExprOnContainer(
|
||||
StringRef MethodName, llvm::ArrayRef<StringRef> ContainerNames) {
|
||||
auto cxxMemberCallExprOnContainer(StringRef MethodName,
|
||||
llvm::ArrayRef<StringRef> ContainerNames) {
|
||||
return cxxMemberCallExpr(
|
||||
hasDeclaration(functionDecl(hasName(MethodName))),
|
||||
on(hasTypeOrPointeeType(hasWantedType(ContainerNames))));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//===--- UseEqualsDefaultCheck.h - clang-tidy--------------------------*- C++ -*-===//
|
||||
//===--- UseEqualsDefaultCheck.h - clang-tidy---------------------*- C++-*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//===--- UseEqualsDeleteCheck.h - clang-tidy---------------------------*- C++ -*-===//
|
||||
//===--- UseEqualsDeleteCheck.h - clang-tidy----------------------*- C++-*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
||||
@@ -316,7 +316,6 @@ findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
// If the return type has no local qualifiers, it's source range is accurate.
|
||||
if (!hasAnyNestedLocalQualifiers(F.getReturnType()))
|
||||
return ReturnTypeRange;
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
||||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
||||
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
||||
|
||||
private:
|
||||
const bool SafeMode;
|
||||
};
|
||||
|
||||
@@ -39,8 +39,8 @@ void UseUncaughtExceptionsCheck::registerMatchers(MatchFinder *Finder) {
|
||||
this);
|
||||
// CallExpr in initialisation list: warning, fix-it with avoiding narrowing
|
||||
// conversions.
|
||||
Finder->addMatcher(callExpr(DirectCallToUncaughtException,
|
||||
hasAncestor(initListExpr()))
|
||||
Finder->addMatcher(
|
||||
callExpr(DirectCallToUncaughtException, hasAncestor(initListExpr()))
|
||||
.bind("init_call_expr"),
|
||||
this);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
|
||||
namespace clang::tidy::modernize {
|
||||
|
||||
/// This check will warn on calls to std::uncaught_exception and replace them with calls to
|
||||
/// std::uncaught_exceptions, since std::uncaught_exception was deprecated in C++17. In case of
|
||||
/// macro ID there will be only a warning without fixits.
|
||||
/// This check will warn on calls to std::uncaught_exception and replace them
|
||||
/// with calls to std::uncaught_exceptions, since std::uncaught_exception was
|
||||
/// deprecated in C++17. In case of macro ID there will be only a warning
|
||||
/// without fixits.
|
||||
///
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-uncaught-exceptions.html
|
||||
|
||||
@@ -35,14 +35,11 @@ constexpr char DefaultForbiddenSuperClassNames[] =
|
||||
|
||||
} // namespace
|
||||
|
||||
ForbiddenSubclassingCheck::ForbiddenSubclassingCheck(
|
||||
StringRef Name,
|
||||
ForbiddenSubclassingCheck::ForbiddenSubclassingCheck(StringRef Name,
|
||||
ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context),
|
||||
ForbiddenSuperClassNames(
|
||||
utils::options::parseStringList(
|
||||
Options.get("ClassNames", DefaultForbiddenSuperClassNames))) {
|
||||
}
|
||||
ForbiddenSuperClassNames(utils::options::parseStringList(
|
||||
Options.get("ClassNames", DefaultForbiddenSuperClassNames))) {}
|
||||
|
||||
void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) {
|
||||
Finder->addMatcher(
|
||||
@@ -53,26 +50,21 @@ void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) {
|
||||
this);
|
||||
}
|
||||
|
||||
void ForbiddenSubclassingCheck::check(
|
||||
const MatchFinder::MatchResult &Result) {
|
||||
const auto *SubClass = Result.Nodes.getNodeAs<ObjCInterfaceDecl>(
|
||||
"subclass");
|
||||
void ForbiddenSubclassingCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
const auto *SubClass = Result.Nodes.getNodeAs<ObjCInterfaceDecl>("subclass");
|
||||
assert(SubClass != nullptr);
|
||||
const auto *SuperClass = Result.Nodes.getNodeAs<ObjCInterfaceDecl>(
|
||||
"superclass");
|
||||
const auto *SuperClass =
|
||||
Result.Nodes.getNodeAs<ObjCInterfaceDecl>("superclass");
|
||||
assert(SuperClass != nullptr);
|
||||
diag(SubClass->getLocation(),
|
||||
"Objective-C interface %0 subclasses %1, which is not "
|
||||
"intended to be subclassed")
|
||||
<< SubClass
|
||||
<< SuperClass;
|
||||
<< SubClass << SuperClass;
|
||||
}
|
||||
|
||||
void ForbiddenSubclassingCheck::storeOptions(
|
||||
ClangTidyOptions::OptionMap &Opts) {
|
||||
Options.store(
|
||||
Opts,
|
||||
"ForbiddenSuperClassNames",
|
||||
Options.store(Opts, "ForbiddenSuperClassNames",
|
||||
utils::options::serializeStringList(ForbiddenSuperClassNames));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,22 +35,19 @@ public:
|
||||
"objc-dealloc-in-category");
|
||||
CheckFactories.registerCheck<ForbiddenSubclassingCheck>(
|
||||
"objc-forbidden-subclassing");
|
||||
CheckFactories.registerCheck<MissingHashCheck>(
|
||||
"objc-missing-hash");
|
||||
CheckFactories.registerCheck<MissingHashCheck>("objc-missing-hash");
|
||||
CheckFactories.registerCheck<NSDateFormatterCheck>("objc-nsdate-formatter");
|
||||
CheckFactories.registerCheck<NSInvocationArgumentLifetimeCheck>(
|
||||
"objc-nsinvocation-argument-lifetime");
|
||||
CheckFactories.registerCheck<PropertyDeclarationCheck>(
|
||||
"objc-property-declaration");
|
||||
CheckFactories.registerCheck<SuperSelfCheck>(
|
||||
"objc-super-self");
|
||||
CheckFactories.registerCheck<SuperSelfCheck>("objc-super-self");
|
||||
}
|
||||
};
|
||||
|
||||
// Register the ObjCTidyModule using this statically initialized variable.
|
||||
static ClangTidyModuleRegistry::Add<ObjCModule> X(
|
||||
"objc-module",
|
||||
"Adds Objective-C lint checks.");
|
||||
static ClangTidyModuleRegistry::Add<ObjCModule>
|
||||
X("objc-module", "Adds Objective-C lint checks.");
|
||||
|
||||
} // namespace objc
|
||||
|
||||
|
||||
@@ -65,8 +65,7 @@ void ImplicitConversionInLoopCheck::check(
|
||||
const MatchFinder::MatchResult &Result) {
|
||||
const auto *VD = Result.Nodes.getNodeAs<VarDecl>("faulty-var");
|
||||
const auto *Init = Result.Nodes.getNodeAs<Expr>("init");
|
||||
const auto *OperatorCall =
|
||||
Result.Nodes.getNodeAs<Expr>("operator-call");
|
||||
const auto *OperatorCall = Result.Nodes.getNodeAs<Expr>("operator-call");
|
||||
|
||||
if (const auto *Cleanup = dyn_cast<ExprWithCleanups>(Init))
|
||||
Init = Cleanup->getSubExpr();
|
||||
|
||||
@@ -126,8 +126,7 @@ void InefficientVectorOperationCheck::addMatcher(
|
||||
//
|
||||
// FIXME: Support more types of counter-based loops like decrement loops.
|
||||
Finder->addMatcher(
|
||||
forStmt(
|
||||
hasLoopInit(LoopVarInit),
|
||||
forStmt(hasLoopInit(LoopVarInit),
|
||||
hasCondition(binaryOperator(
|
||||
hasOperatorName("<"), hasLHS(RefersToLoopVar),
|
||||
hasRHS(expr(unless(hasDescendant(expr(RefersToLoopVar))))
|
||||
|
||||
@@ -111,7 +111,8 @@ AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
|
||||
// an alias to one of its arguments and the arguments need to be checked
|
||||
// for const use as well.
|
||||
return callExpr(argumentCountIs(0),
|
||||
callee(functionDecl(returns(hasCanonicalType(matchers::isReferenceToConst())),
|
||||
callee(functionDecl(returns(hasCanonicalType(
|
||||
matchers::isReferenceToConst())),
|
||||
unless(cxxMethodDecl(unless(isStatic()))))
|
||||
.bind(FunctionDeclId)))
|
||||
.bind(InitFunctionCallId);
|
||||
@@ -234,12 +235,14 @@ UnnecessaryCopyInitialization::UnnecessaryCopyInitialization(
|
||||
Options.get("ExcludedContainerTypes", ""))) {}
|
||||
|
||||
void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
|
||||
auto LocalVarCopiedFrom = [this](const ast_matchers::internal::Matcher<Expr> &CopyCtorArg) {
|
||||
auto LocalVarCopiedFrom =
|
||||
[this](const ast_matchers::internal::Matcher<Expr> &CopyCtorArg) {
|
||||
return compoundStmt(
|
||||
forEachDescendant(
|
||||
declStmt(
|
||||
unless(has(decompositionDecl())),
|
||||
has(varDecl(hasLocalStorage(),
|
||||
has(varDecl(
|
||||
hasLocalStorage(),
|
||||
hasType(qualType(
|
||||
hasCanonicalType(allOf(
|
||||
matchers::isExpensiveToCopy(),
|
||||
|
||||
@@ -46,7 +46,8 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isBitFieldWidth(const clang::ast_matchers::MatchFinder::MatchResult &Result,
|
||||
bool
|
||||
isBitFieldWidth(const clang::ast_matchers::MatchFinder::MatchResult &Result,
|
||||
const IntegerLiteral &Literal) const;
|
||||
|
||||
bool isUserDefinedLiteral(
|
||||
|
||||
@@ -50,10 +50,9 @@ std::optional<Token> findQualToken(const VarDecl *Decl, Qualifier Qual,
|
||||
if (FileRange.isInvalid())
|
||||
return std::nullopt;
|
||||
|
||||
tok::TokenKind Tok =
|
||||
Qual == Qualifier::Const
|
||||
? tok::kw_const
|
||||
: Qual == Qualifier::Volatile ? tok::kw_volatile : tok::kw_restrict;
|
||||
tok::TokenKind Tok = Qual == Qualifier::Const ? tok::kw_const
|
||||
: Qual == Qualifier::Volatile ? tok::kw_volatile
|
||||
: tok::kw_restrict;
|
||||
|
||||
return utils::lexer::getQualifyingToken(Tok, FileRange, *Result.Context,
|
||||
*Result.SourceManager);
|
||||
|
||||
@@ -13,7 +13,8 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang::tidy::readability {
|
||||
|
||||
void RedundantFunctionPtrDereferenceCheck::registerMatchers(MatchFinder *Finder) {
|
||||
void RedundantFunctionPtrDereferenceCheck::registerMatchers(
|
||||
MatchFinder *Finder) {
|
||||
Finder->addMatcher(
|
||||
traverse(TK_AsIs, unaryOperator(hasOperatorName("*"),
|
||||
has(implicitCastExpr(hasCastKind(
|
||||
@@ -22,7 +23,8 @@ void RedundantFunctionPtrDereferenceCheck::registerMatchers(MatchFinder *Finder)
|
||||
this);
|
||||
}
|
||||
|
||||
void RedundantFunctionPtrDereferenceCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
void RedundantFunctionPtrDereferenceCheck::check(
|
||||
const MatchFinder::MatchResult &Result) {
|
||||
const auto *Operator = Result.Nodes.getNodeAs<UnaryOperator>("op");
|
||||
diag(Operator->getOperatorLoc(),
|
||||
"redundant repeated dereference of function pointer")
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace clang::tidy::readability {
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-function-ptr-dereference.html
|
||||
class RedundantFunctionPtrDereferenceCheck : public ClangTidyCheck {
|
||||
public:
|
||||
RedundantFunctionPtrDereferenceCheck(StringRef Name, ClangTidyContext *Context)
|
||||
RedundantFunctionPtrDereferenceCheck(StringRef Name,
|
||||
ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context) {}
|
||||
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
||||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
||||
|
||||
@@ -52,11 +52,10 @@ void RedundantStringCStrCheck::registerMatchers(
|
||||
const auto StringConstructorExpr = expr(anyOf(
|
||||
cxxConstructExpr(argumentCountIs(1),
|
||||
hasDeclaration(cxxMethodDecl(hasName("basic_string")))),
|
||||
cxxConstructExpr(
|
||||
argumentCountIs(2),
|
||||
cxxConstructExpr(argumentCountIs(2),
|
||||
hasDeclaration(cxxMethodDecl(hasName("basic_string"))),
|
||||
// If present, the second argument is the alloc object which must not
|
||||
// be present explicitly.
|
||||
// If present, the second argument is the alloc object
|
||||
// which must not be present explicitly.
|
||||
hasArgument(1, cxxDefaultArgExpr()))));
|
||||
|
||||
// Match string constructor.
|
||||
@@ -105,8 +104,9 @@ void RedundantStringCStrCheck::registerMatchers(
|
||||
|
||||
// Detect: 'dst.append(str.c_str())' -> 'dst.append(str)'
|
||||
Finder->addMatcher(
|
||||
cxxMemberCallExpr(on(StringExpr), callee(decl(cxxMethodDecl(hasAnyName(
|
||||
"append", "assign", "compare")))),
|
||||
cxxMemberCallExpr(on(StringExpr),
|
||||
callee(decl(cxxMethodDecl(
|
||||
hasAnyName("append", "assign", "compare")))),
|
||||
argumentCountIs(1), hasArgument(0, StringCStrCallExpr)),
|
||||
this);
|
||||
|
||||
|
||||
@@ -337,8 +337,7 @@ Allow empty enabled checks. This suppresses
|
||||
the "no checks enabled" error when disabling
|
||||
all of the checks.
|
||||
)"),
|
||||
cl::init(false),
|
||||
cl::cat(ClangTidyCategory));
|
||||
cl::init(false), cl::cat(ClangTidyCategory));
|
||||
|
||||
namespace clang::tidy {
|
||||
|
||||
@@ -370,8 +369,8 @@ static void printStats(const ClangTidyStats &Stats) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
|
||||
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
||||
static std::unique_ptr<ClangTidyOptionsProvider>
|
||||
createOptionsProvider(llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
||||
ClangTidyGlobalOptions GlobalOptions;
|
||||
if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
|
||||
llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
|
||||
|
||||
@@ -48,8 +48,7 @@ StringRef makeCanonicalName(StringRef Str, IncludeSorter::IncludeStyle Style) {
|
||||
if (StartIndex == StringRef::npos) {
|
||||
StartIndex = 0;
|
||||
}
|
||||
return Canonical.substr(
|
||||
0, Canonical.find_first_of('+', StartIndex));
|
||||
return Canonical.substr(0, Canonical.find_first_of('+', StartIndex));
|
||||
}
|
||||
return removeFirstSuffix(
|
||||
removeFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}),
|
||||
|
||||
@@ -41,8 +41,7 @@ std::optional<bool> isExpensiveToCopy(QualType Type,
|
||||
return std::nullopt;
|
||||
return !Type.isTriviallyCopyableType(Context) &&
|
||||
!classHasTrivialCopyAndDestroy(Type) &&
|
||||
!hasDeletedCopyConstructor(Type) &&
|
||||
!Type->isObjCLifetimeType();
|
||||
!hasDeletedCopyConstructor(Type) && !Type->isObjCLifetimeType();
|
||||
}
|
||||
|
||||
bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
|
||||
|
||||
Reference in New Issue
Block a user