[clang-tidy] Change checks to use new isLanguageVersionSupported restriction

Summary: Modifies all checks that are language version dependent to use `isLanguageVersionSupported`

Reviewers: jdoerfert, lebedev.ri, aaron.ballman, gribozavr2, Eugene.Zelenko

Reviewed By: gribozavr2

Subscribers: wuzish, nemanjai, xazax.hun, hiraditya, kbarton, steven_wu, dexonsmith, arphaman, lebedev.ri, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75340
This commit is contained in:
Nathan James 2020-03-03 16:39:32 +00:00
parent b4b9fa5e11
commit e40a742a50
254 changed files with 400 additions and 477 deletions

View File

@ -17,9 +17,6 @@ namespace abseil {
using namespace clang::ast_matchers;
void DurationDivisionCheck::registerMatchers(MatchFinder *finder) {
if (!getLangOpts().CPlusPlus)
return;
const auto DurationExpr =
expr(hasType(cxxRecordDecl(hasName("::absl::Duration"))));
finder->addMatcher(

View File

@ -23,6 +23,9 @@ namespace abseil {
class DurationDivisionCheck : public ClangTidyCheck {
public:
using ClangTidyCheck::ClangTidyCheck;
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &result) override;
};

View File

@ -57,9 +57,6 @@ llvm::Optional<std::string> makeCharacterLiteral(const StringLiteral *Literal,
} // anonymous namespace
void FasterStrsplitDelimiterCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// Binds to one character string literals.
const auto SingleChar =
expr(ignoringParenCasts(stringLiteral(lengthIsOne()).bind("Literal")));

View File

@ -24,6 +24,9 @@ class FasterStrsplitDelimiterCheck : public ClangTidyCheck {
public:
FasterStrsplitDelimiterCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -18,9 +18,6 @@ namespace tidy {
namespace abseil {
void NoInternalDependenciesCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// TODO: refactor matcher to be configurable or just match on any internal
// access from outside the enclosing namespace.

View File

@ -24,6 +24,9 @@ class NoInternalDependenciesCheck : public ClangTidyCheck {
public:
NoInternalDependenciesCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -18,9 +18,6 @@ namespace tidy {
namespace abseil {
void NoNamespaceCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
namespaceDecl(hasName("::absl"), unless(isInAbseilFile()))
.bind("abslNamespace"),

View File

@ -24,6 +24,9 @@ class NoNamespaceCheck : public ClangTidyCheck {
public:
NoNamespaceCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -25,8 +25,6 @@ namespace abseil {
// argument.
void RedundantStrcatCallsCheck::registerMatchers(MatchFinder* Finder) {
if (!getLangOpts().CPlusPlus)
return;
const auto CallToStrcat =
callExpr(callee(functionDecl(hasName("::absl::StrCat"))));
const auto CallToStrappend =

View File

@ -27,6 +27,9 @@ class RedundantStrcatCallsCheck : public ClangTidyCheck {
public:
RedundantStrcatCallsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -42,8 +42,6 @@ AST_MATCHER_P(Stmt, IgnoringTemporaries, ast_matchers::internal::Matcher<Stmt>,
// str.append(StrCat(...))
void StrCatAppendCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
const auto StrCat = functionDecl(hasName("::absl::StrCat"));
// The arguments of absl::StrCat are implicitly converted to AlphaNum. This
// matches to the arguments because of that behavior.

View File

@ -24,6 +24,9 @@ class StrCatAppendCheck : public ClangTidyCheck {
public:
StrCatAppendCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -18,9 +18,6 @@ namespace tidy {
namespace abseil {
void UpgradeDurationConversionsCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// For the arithmetic calls, we match only the uses of the templated operators
// where the template parameter is not a built-in type. This means the
// instantiation makes use of an available user defined conversion to

View File

@ -25,6 +25,9 @@ class UpgradeDurationConversionsCheck : public ClangTidyCheck {
public:
UpgradeDurationConversionsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -22,9 +22,6 @@ AST_MATCHER(Type, isStrictlyInteger) {
} // namespace
void UseToStringCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
callExpr(
hasDeclaration(functionDecl(

View File

@ -25,6 +25,9 @@ class UseToStringCheck : public ClangTidyCheck {
public:
UseToStringCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -18,9 +18,6 @@ namespace tidy {
namespace bugprone {
void CopyConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// In the future this might be extended to move constructors?
Finder->addMatcher(
cxxConstructorDecl(

View File

@ -24,6 +24,9 @@ class CopyConstructorInitCheck : public ClangTidyCheck {
public:
CopyConstructorInitCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -44,8 +44,6 @@ void DynamicStaticInitializersCheck::storeOptions(
}
void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus || getLangOpts().ThreadsafeStatics)
return;
Finder->addMatcher(
varDecl(hasGlobalStorage(), unless(hasConstantDeclaration())).bind("var"),
this);

View File

@ -27,6 +27,9 @@ namespace bugprone {
class DynamicStaticInitializersCheck : public ClangTidyCheck {
public:
DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -52,9 +52,6 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus || !getLangOpts().CXXExceptions)
return;
Finder->addMatcher(
functionDecl(anyOf(isNoThrow(), cxxDestructorDecl(),
cxxConstructorDecl(isMoveConstructor()),

View File

@ -27,6 +27,9 @@ namespace bugprone {
class ExceptionEscapeCheck : public ClangTidyCheck {
public:
ExceptionEscapeCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus && LangOpts.CXXExceptions;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -60,10 +60,6 @@ AST_MATCHER_P(TemplateTypeParmDecl, hasDefaultArgument,
} // namespace
void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
// Forwarding references require C++11 or later.
if (!getLangOpts().CPlusPlus11)
return;
auto ForwardingRefParm =
parmVarDecl(
hasType(qualType(rValueReferenceType(),

View File

@ -30,6 +30,9 @@ class ForwardingReferenceOverloadCheck : public ClangTidyCheck {
public:
ForwardingReferenceOverloadCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -18,11 +18,6 @@ namespace tidy {
namespace bugprone {
void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
// Only register the matchers for C++; the functionality currently does not
// provide any benefit to other languages, despite being benign.
if (!getLangOpts().CPlusPlus)
return;
const auto EndCall =
callExpr(
callee(functionDecl(hasAnyName("remove", "remove_if", "unique"))),

View File

@ -26,6 +26,9 @@ class InaccurateEraseCheck : public ClangTidyCheck {
public:
InaccurateEraseCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -67,9 +67,6 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
}
void MoveForwardingReferenceCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus11)
return;
// Matches a ParmVarDecl for a forwarding reference, i.e. a non-const rvalue
// reference of a function template parameter type.
auto ForwardingReferenceParmMatcher =

View File

@ -37,6 +37,9 @@ class MoveForwardingReferenceCheck : public ClangTidyCheck {
public:
MoveForwardingReferenceCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -35,9 +35,6 @@ void StringConstructorCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void StringConstructorCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
const auto ZeroExpr = expr(ignoringParenImpCasts(integerLiteral(equals(0))));
const auto CharExpr = expr(ignoringParenImpCasts(characterLiteral()));
const auto NegativeExpr = expr(ignoringParenImpCasts(

View File

@ -22,6 +22,9 @@ namespace bugprone {
class StringConstructorCheck : public ClangTidyCheck {
public:
StringConstructorCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -18,8 +18,6 @@ namespace tidy {
namespace bugprone {
void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
cxxOperatorCallExpr(
anyOf(hasOverloadedOperatorName("="),

View File

@ -23,6 +23,9 @@ class StringIntegerAssignmentCheck : public ClangTidyCheck {
public:
StringIntegerAssignmentCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -17,9 +17,6 @@ namespace tidy {
namespace bugprone {
void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
auto CtorInitializerList =
cxxConstructorDecl(hasAnyConstructorInitializer(anything()));

View File

@ -24,6 +24,9 @@ class ThrowKeywordMissingCheck : public ClangTidyCheck {
public:
ThrowKeywordMissingCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -53,11 +53,6 @@ void UndelegatedConstructorCheck::registerMatchers(MatchFinder *Finder) {
// depending on the type's destructor and the number of arguments on the
// constructor call, this is handled by ignoringTemporaryExpr. Ignore template
// instantiations to reduce the number of duplicated warnings.
//
// Only register the matchers for C++11; the functionality currently does not
// provide any benefit to other languages, despite being benign.
if (!getLangOpts().CPlusPlus11)
return;
Finder->addMatcher(
compoundStmt(

View File

@ -24,6 +24,9 @@ class UndelegatedConstructorCheck : public ClangTidyCheck {
public:
UndelegatedConstructorCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -29,9 +29,6 @@ void UnhandledSelfAssignmentCheck::storeOptions(
}
void UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// We don't care about deleted, default or implicit operator implementations.
const auto IsUserDefined = cxxMethodDecl(
isDefinition(), unless(anyOf(isDeleted(), isImplicit(), isDefaulted())));

View File

@ -25,6 +25,9 @@ class UnhandledSelfAssignmentCheck : public ClangTidyCheck {
public:
UnhandledSelfAssignmentCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -24,11 +24,6 @@ AST_MATCHER(CXXRecordDecl, hasNonTrivialDestructor) {
} // namespace
void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
// Only register the matchers for C++; the functionality currently does not
// provide any benefit to other languages, despite being benign.
if (!getLangOpts().CPlusPlus)
return;
// Look for temporaries that are constructed in-place and immediately
// destroyed. Look for temporaries created by a functional cast but not for
// those returned from a call.

View File

@ -23,6 +23,9 @@ class UnusedRaiiCheck : public ClangTidyCheck {
public:
UnusedRaiiCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -396,9 +396,6 @@ static void emitDiagnostic(const Expr *MovingCall, const DeclRefExpr *MoveArg,
}
void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus11)
return;
auto CallMoveMatcher =
callExpr(callee(functionDecl(hasName("::std::move"))), argumentCountIs(1),
hasArgument(0, declRefExpr().bind("arg")),

View File

@ -24,6 +24,9 @@ class UseAfterMoveCheck : public ClangTidyCheck {
public:
UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -215,9 +215,6 @@ bool VirtualNearMissCheck::isOverriddenByDerivedClass(
}
void VirtualNearMissCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
cxxMethodDecl(
unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),

View File

@ -27,6 +27,9 @@ class VirtualNearMissCheck : public ClangTidyCheck {
public:
VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -17,10 +17,6 @@ namespace tidy {
namespace cert {
void DefaultOperatorNewAlignmentCheck::registerMatchers(MatchFinder *Finder) {
// Check not applicable in C++17 (or newer).
if (getLangOpts().CPlusPlus17)
return;
Finder->addMatcher(
cxxNewExpr(unless(hasAnyPlacementArg(anything()))).bind("new"), this);
}

View File

@ -24,6 +24,9 @@ class DefaultOperatorNewAlignmentCheck : public ClangTidyCheck {
public:
DefaultOperatorNewAlignmentCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return !LangOpts.CPlusPlus17;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -17,9 +17,6 @@ namespace tidy {
namespace cert {
void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
namespaceDecl(unless(isExpansionInSystemHeader()),
anyOf(hasName("std"), hasName("posix")),

View File

@ -24,6 +24,9 @@ class DontModifyStdNamespaceCheck : public ClangTidyCheck {
public:
DontModifyStdNamespaceCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -21,9 +21,6 @@ static constexpr llvm::StringLiteral MutatingOperatorName = "MutatingOp";
static constexpr llvm::StringLiteral MutatingCallName = "MutatingCall";
void MutatingCopyCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
const auto MemberExprOrSourceObject = anyOf(
memberExpr(),
declRefExpr(to(decl(equalsBoundNode(std::string(SourceDeclName))))));

View File

@ -24,6 +24,9 @@ class MutatingCopyCheck : public ClangTidyCheck {
public:
MutatingCopyCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -85,9 +85,6 @@ void NonTrivialTypesLibcMemoryCallsCheck::storeOptions(
void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus || getLangOpts().ObjC)
return;
using namespace ast_matchers::internal;
auto IsStructPointer = [](Matcher<CXXRecordDecl> Constraint = anything(),
bool Bind = false) {

View File

@ -24,6 +24,9 @@ class NonTrivialTypesLibcMemoryCallsCheck : public ClangTidyCheck {
public:
NonTrivialTypesLibcMemoryCallsCheck(StringRef Name,
ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus && !LangOpts.ObjC;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -18,9 +18,6 @@ namespace tidy {
namespace cert {
void PostfixOperatorCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(functionDecl(anyOf(hasOverloadedOperatorName("++"),
hasOverloadedOperatorName("--")),
unless(isInstantiated()))

View File

@ -24,6 +24,9 @@ class PostfixOperatorCheck : public ClangTidyCheck {
public:
PostfixOperatorCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -44,22 +44,12 @@ public:
void SetLongJmpCheck::registerPPCallbacks(const SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
// This checker only applies to C++, where exception handling is a superior
// solution to setjmp/longjmp calls.
if (!getLangOpts().CPlusPlus)
return;
// Per [headers]p5, setjmp must be exposed as a macro instead of a function,
// despite the allowance in C for setjmp to also be an extern function.
PP->addPPCallbacks(std::make_unique<SetJmpMacroCallbacks>(*this));
}
void SetLongJmpCheck::registerMatchers(MatchFinder *Finder) {
// This checker only applies to C++, where exception handling is a superior
// solution to setjmp/longjmp calls.
if (!getLangOpts().CPlusPlus)
return;
// In case there is an implementation that happens to define setjmp as a
// function instead of a macro, this will also catch use of it. However, we
// are primarily searching for uses of longjmp.

View File

@ -23,6 +23,9 @@ class SetLongJmpCheck : public ClangTidyCheck {
public:
SetLongJmpCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,

View File

@ -18,9 +18,6 @@ namespace tidy {
namespace cert {
void StaticObjectExceptionCheck::registerMatchers(MatchFinder *Finder) {
if ((!getLangOpts().CPlusPlus) || (!getLangOpts().CXXExceptions))
return;
// Match any static or thread_local variable declaration that has an
// initializer that can throw.
Finder->addMatcher(

View File

@ -24,6 +24,9 @@ class StaticObjectExceptionCheck : public ClangTidyCheck {
public:
StaticObjectExceptionCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return getLangOpts().CPlusPlus && getLangOpts().CXXExceptions;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -18,9 +18,6 @@ namespace tidy {
namespace cert {
void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
cxxThrowExpr(has(ignoringParenImpCasts(
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(

View File

@ -23,6 +23,9 @@ class ThrownExceptionTypeCheck : public ClangTidyCheck {
public:
ThrownExceptionTypeCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -17,9 +17,6 @@ namespace tidy {
namespace cert {
void VariadicFunctionDefCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// We only care about function *definitions* that are variadic, and do not
// have extern "C" language linkage.
Finder->addMatcher(

View File

@ -23,6 +23,9 @@ class VariadicFunctionDefCheck : public ClangTidyCheck {
public:
VariadicFunctionDefCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -23,9 +23,6 @@ AST_MATCHER(GotoStmt, isForwardJumping) {
} // namespace
void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// TODO: This check does not recognize `IndirectGotoStmt` which is a
// GNU extension. These must be matched separately and an AST matcher
// is currently missing for them.

View File

@ -24,6 +24,9 @@ class AvoidGotoCheck : public ClangTidyCheck {
public:
AvoidGotoCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -71,9 +71,6 @@ void MacroUsageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
void MacroUsageCheck::registerPPCallbacks(const SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
if (!getLangOpts().CPlusPlus11)
return;
PP->addPPCallbacks(std::make_unique<MacroUsageCallbacks>(
this, SM, AllowedRegexp, CheckCapsOnly, IgnoreCommandLineMacros));
}

View File

@ -29,6 +29,9 @@ public:
AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")),
CheckCapsOnly(Options.get("CheckCapsOnly", 0)),
IgnoreCommandLineMacros(Options.get("IgnoreCommandLineMacros", 1)) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;

View File

@ -37,10 +37,6 @@ void NoMallocCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void NoMallocCheck::registerMatchers(MatchFinder *Finder) {
// C-style memory management is only problematic in C++.
if (!getLangOpts().CPlusPlus)
return;
// Registering malloc, will suggest RAII.
Finder->addMatcher(callExpr(callee(functionDecl(hasAnyListedName(AllocList))))
.bind("allocation"),

View File

@ -33,6 +33,10 @@ public:
ReallocList(Options.get("Reallocations", "::realloc")),
DeallocList(Options.get("Deallocations", "::free")) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
/// Make configuration of checker discoverable.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

View File

@ -39,9 +39,6 @@ void OwningMemoryCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
/// Match common cases, where the owner semantic is relevant, like function
/// calls, delete expressions and others.
void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus11)
return;
const auto OwnerDecl = typeAliasTemplateDecl(hasName("::gsl::owner"));
const auto IsOwnerType = hasType(OwnerDecl);

View File

@ -30,6 +30,9 @@ public:
LegacyResourceConsumers(Options.get(
"LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
/// Make configuration of checker discoverable.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

View File

@ -49,9 +49,6 @@ AST_MATCHER_P(Expr, hasParentIgnoringImpCasts,
} // namespace
void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// The only allowed array to pointer decay
// 1) just before array subscription
// 2) inside a range-for over an array

View File

@ -23,6 +23,9 @@ class ProBoundsArrayToPointerDecayCheck : public ClangTidyCheck {
public:
ProBoundsArrayToPointerDecayCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -32,18 +32,12 @@ void ProBoundsConstantArrayIndexCheck::storeOptions(
void ProBoundsConstantArrayIndexCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
if (!getLangOpts().CPlusPlus)
return;
Inserter = std::make_unique<utils::IncludeInserter>(SM, getLangOpts(),
IncludeStyle);
PP->addPPCallbacks(Inserter->CreatePPCallbacks());
}
void ProBoundsConstantArrayIndexCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
// Note: if a struct contains an array member, the compiler-generated
// constructor has an arraySubscriptExpr.
Finder->addMatcher(

View File

@ -28,6 +28,9 @@ class ProBoundsConstantArrayIndexCheck : public ClangTidyCheck {
public:
ProBoundsConstantArrayIndexCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;

View File

@ -17,9 +17,6 @@ namespace tidy {
namespace cppcoreguidelines {
void ProTypeConstCastCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(cxxConstCastExpr().bind("cast"), this);
}

View File

@ -23,6 +23,9 @@ class ProTypeConstCastCheck : public ClangTidyCheck {
public:
ProTypeConstCastCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -30,9 +30,6 @@ static bool needsConstCast(QualType SourceType, QualType DestType) {
}
void ProTypeCstyleCastCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
cStyleCastExpr(unless(isInTemplateInstantiation())).bind("cast"), this);
}

View File

@ -24,6 +24,9 @@ class ProTypeCstyleCastCheck : public ClangTidyCheck {
public:
ProTypeCstyleCastCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -254,9 +254,6 @@ ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name,
UseAssignment(Options.getLocalOrGlobal("UseAssignment", false)) {}
void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
auto IsUserProvidedNonDelegatingConstructor =
allOf(isUserProvided(),
unless(anyOf(isInstantiated(), isDelegatingConstructor())));

View File

@ -33,6 +33,9 @@ namespace cppcoreguidelines {
class ProTypeMemberInitCheck : public ClangTidyCheck {
public:
ProTypeMemberInitCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

View File

@ -17,9 +17,6 @@ namespace tidy {
namespace cppcoreguidelines {
void ProTypeReinterpretCastCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(cxxReinterpretCastExpr().bind("cast"), this);
}

View File

@ -23,6 +23,9 @@ class ProTypeReinterpretCastCheck : public ClangTidyCheck {
public:
ProTypeReinterpretCastCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -17,9 +17,6 @@ namespace tidy {
namespace cppcoreguidelines {
void ProTypeStaticCastDowncastCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
cxxStaticCastExpr(unless(isInTemplateInstantiation())).bind("cast"),
this);

View File

@ -24,6 +24,9 @@ class ProTypeStaticCastDowncastCheck : public ClangTidyCheck {
public:
ProTypeStaticCastDowncastCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -17,9 +17,6 @@ namespace tidy {
namespace cppcoreguidelines {
void ProTypeUnionAccessCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
memberExpr(hasObjectExpression(hasType(recordDecl(isUnion()))))
.bind("expr"),

View File

@ -24,6 +24,9 @@ class ProTypeUnionAccessCheck : public ClangTidyCheck {
public:
ProTypeUnionAccessCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -19,9 +19,6 @@ namespace cppcoreguidelines {
const internal::VariadicDynCastAllOfMatcher<Stmt, VAArgExpr> vAArgExpr;
void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(vAArgExpr().bind("va_use"), this);
Finder->addMatcher(

View File

@ -24,6 +24,9 @@ class ProTypeVarargCheck : public ClangTidyCheck {
public:
ProTypeVarargCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -34,8 +34,6 @@ void SpecialMemberFunctionsCheck::storeOptions(
}
void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
Finder->addMatcher(
cxxRecordDecl(
eachOf(

View File

@ -25,6 +25,9 @@ namespace cppcoreguidelines {
class SpecialMemberFunctionsCheck : public ClangTidyCheck {
public:
SpecialMemberFunctionsCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -88,10 +88,6 @@ bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
}
void MultipleInheritanceCheck::registerMatchers(MatchFinder *Finder) {
// Requires C++.
if (!getLangOpts().CPlusPlus)
return;
// Match declarations which have bases.
Finder->addMatcher(
cxxRecordDecl(allOf(hasBases(), isDefinition())).bind("decl"), this);

View File

@ -23,6 +23,9 @@ class MultipleInheritanceCheck : public ClangTidyCheck {
public:
MultipleInheritanceCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

View File

@ -28,11 +28,6 @@ void StaticallyConstructedObjectsCheck::registerMatchers(MatchFinder *Finder) {
// Constructing global, non-trivial objects with static storage is
// disallowed, unless the object is statically initialized with a constexpr
// constructor or has no explicit constructor.
// Constexpr requires C++11 or later.
if (!getLangOpts().CPlusPlus11)
return;
Finder->addMatcher(varDecl(
// Match global, statically stored objects...
isGlobalStatic(),

View File

@ -25,6 +25,9 @@ class StaticallyConstructedObjectsCheck : public ClangTidyCheck {
public:
StaticallyConstructedObjectsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -24,11 +24,6 @@ AST_MATCHER(FunctionDecl, hasTrailingReturn) {
} // namespace
void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
// Requires C++11 or later.
if (!getLangOpts().CPlusPlus11)
return;
// Functions that have trailing returns are disallowed, except for those
// using decltype specifiers and lambda with otherwise unutterable
// return types.

View File

@ -25,6 +25,9 @@ class TrailingReturnCheck : public ClangTidyCheck {
public:
TrailingReturnCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -94,9 +94,6 @@ static FixItHint getCallFixItHint(const ObjCMessageExpr *Expr,
}
void AvoidNSObjectNewCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().ObjC)
return;
// Add two matchers, to catch calls to +new and implementations of +new.
Finder->addMatcher(
objcMessageExpr(isClassMessage(), hasSelector("new")).bind("new_call"),

View File

@ -26,6 +26,9 @@ class AvoidNSObjectNewCheck : public ClangTidyCheck {
public:
AvoidNSObjectNewCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.ObjC;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

View File

@ -18,9 +18,6 @@ namespace google {
namespace objc {
void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
// this check should only be applied to ObjC sources.
if (!getLangOpts().ObjC)
return;
Finder->addMatcher(objcThrowStmt().bind("throwStmt"), this);
Finder->addMatcher(

View File

@ -26,6 +26,9 @@ class AvoidThrowingObjCExceptionCheck : public ClangTidyCheck {
public:
AvoidThrowingObjCExceptionCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.ObjC;
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};

Some files were not shown because too many files have changed in this diff Show More