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