[clang-tidy][NFC] run clang-format over 'cert', 'cppcore', 'fuchsia',… (#143316)
… 'google' checks
This commit is contained in:
@@ -250,8 +250,7 @@ public:
|
||||
"cert-dcl51-cpp");
|
||||
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
|
||||
"cert-dcl54-cpp");
|
||||
CheckFactories.registerCheck<DontModifyStdNamespaceCheck>(
|
||||
"cert-dcl58-cpp");
|
||||
CheckFactories.registerCheck<DontModifyStdNamespaceCheck>("cert-dcl58-cpp");
|
||||
CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
|
||||
"cert-dcl59-cpp");
|
||||
// ERR
|
||||
@@ -278,8 +277,7 @@ public:
|
||||
"cert-oop54-cpp");
|
||||
CheckFactories.registerCheck<NonTrivialTypesLibcMemoryCallsCheck>(
|
||||
"cert-oop57-cpp");
|
||||
CheckFactories.registerCheck<MutatingCopyCheck>(
|
||||
"cert-oop58-cpp");
|
||||
CheckFactories.registerCheck<MutatingCopyCheck>("cert-oop58-cpp");
|
||||
|
||||
// C checkers
|
||||
// ARR
|
||||
|
||||
@@ -433,21 +433,22 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
|
||||
// Gather all fields (direct and indirect) that need to be initialized.
|
||||
SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
|
||||
bool AnyMemberHasInitPerUnion = false;
|
||||
forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
|
||||
AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
|
||||
if (IgnoreArrays && F->getType()->isArrayType())
|
||||
return;
|
||||
if (F->hasInClassInitializer() && F->getParent()->isUnion()) {
|
||||
AnyMemberHasInitPerUnion = true;
|
||||
removeFieldInitialized(F, FieldsToInit);
|
||||
}
|
||||
if (!F->hasInClassInitializer() &&
|
||||
utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
|
||||
Context) &&
|
||||
!isEmpty(Context, F->getType()) && !F->isUnnamedBitField() &&
|
||||
!AnyMemberHasInitPerUnion)
|
||||
FieldsToInit.insert(F);
|
||||
});
|
||||
forEachFieldWithFilter(
|
||||
ClassDecl, ClassDecl.fields(), AnyMemberHasInitPerUnion,
|
||||
[&](const FieldDecl *F) {
|
||||
if (IgnoreArrays && F->getType()->isArrayType())
|
||||
return;
|
||||
if (F->hasInClassInitializer() && F->getParent()->isUnion()) {
|
||||
AnyMemberHasInitPerUnion = true;
|
||||
removeFieldInitialized(F, FieldsToInit);
|
||||
}
|
||||
if (!F->hasInClassInitializer() &&
|
||||
utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
|
||||
Context) &&
|
||||
!isEmpty(Context, F->getType()) && !F->isUnnamedBitField() &&
|
||||
!AnyMemberHasInitPerUnion)
|
||||
FieldsToInit.insert(F);
|
||||
});
|
||||
if (FieldsToInit.empty())
|
||||
return;
|
||||
|
||||
@@ -500,17 +501,18 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
|
||||
AnyMemberHasInitPerUnion = false;
|
||||
forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
|
||||
AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
|
||||
if (!FieldsToInit.count(F))
|
||||
return;
|
||||
// Don't suggest fixes for enums because we don't know a good default.
|
||||
// Don't suggest fixes for bitfields because in-class initialization is not
|
||||
// possible until C++20.
|
||||
if (F->getType()->isEnumeralType() ||
|
||||
(!getLangOpts().CPlusPlus20 && F->isBitField()))
|
||||
return;
|
||||
FieldsToFix.insert(F);
|
||||
AnyMemberHasInitPerUnion = true;
|
||||
});
|
||||
if (!FieldsToInit.count(F))
|
||||
return;
|
||||
// Don't suggest fixes for enums because we don't
|
||||
// know a good default. Don't suggest fixes for
|
||||
// bitfields because in-class initialization is not
|
||||
// possible until C++20.
|
||||
if (F->getType()->isEnumeralType() ||
|
||||
(!getLangOpts().CPlusPlus20 && F->isBitField()))
|
||||
return;
|
||||
FieldsToFix.insert(F);
|
||||
AnyMemberHasInitPerUnion = true;
|
||||
});
|
||||
if (FieldsToFix.empty())
|
||||
return;
|
||||
|
||||
|
||||
@@ -14,11 +14,7 @@
|
||||
namespace clang::tidy::cppcoreguidelines {
|
||||
|
||||
/// Flags slicing (incomplete copying of an object's state) of member variables
|
||||
/// or vtable. See:
|
||||
/// - https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es63-dont-slice
|
||||
/// for the former, and
|
||||
/// - https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c145-access-polymorphic-objects-through-pointers-and-references
|
||||
/// for the latter
|
||||
/// or vtable.
|
||||
///
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/slicing.html
|
||||
|
||||
@@ -116,7 +116,8 @@ void SpecialMemberFunctionsCheck::check(
|
||||
if (!MatchedDecl)
|
||||
return;
|
||||
|
||||
ClassDefId ID(MatchedDecl->getLocation(), std::string(MatchedDecl->getName()));
|
||||
ClassDefId ID(MatchedDecl->getLocation(),
|
||||
std::string(MatchedDecl->getName()));
|
||||
|
||||
auto StoreMember = [this, &ID](SpecialMemberFunctionData Data) {
|
||||
llvm::SmallVectorImpl<SpecialMemberFunctionData> &Members =
|
||||
|
||||
@@ -84,13 +84,12 @@ struct DenseMapInfo<
|
||||
clang::tidy::cppcoreguidelines::SpecialMemberFunctionsCheck::ClassDefId;
|
||||
|
||||
static inline ClassDefId getEmptyKey() {
|
||||
return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
|
||||
"EMPTY"};
|
||||
return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(), "EMPTY"};
|
||||
}
|
||||
|
||||
static inline ClassDefId getTombstoneKey() {
|
||||
return {DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
|
||||
"TOMBSTONE"};
|
||||
"TOMBSTONE"};
|
||||
}
|
||||
|
||||
static unsigned getHashValue(ClassDefId Val) {
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace clang::tidy::darwin {
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/darwin/avoid-spinlock.html
|
||||
class AvoidSpinlockCheck : public ClangTidyCheck {
|
||||
public:
|
||||
public:
|
||||
AvoidSpinlockCheck(StringRef Name, ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context) {}
|
||||
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
||||
@@ -28,4 +28,4 @@ class AvoidSpinlockCheck : public ClangTidyCheck {
|
||||
|
||||
} // namespace clang::tidy::darwin
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H
|
||||
|
||||
@@ -18,8 +18,7 @@ namespace darwin {
|
||||
class DarwinModule : public ClangTidyModule {
|
||||
public:
|
||||
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
||||
CheckFactories.registerCheck<AvoidSpinlockCheck>(
|
||||
"darwin-avoid-spinlock");
|
||||
CheckFactories.registerCheck<AvoidSpinlockCheck>("darwin-avoid-spinlock");
|
||||
CheckFactories.registerCheck<DispatchOnceNonstaticCheck>(
|
||||
"darwin-dispatch-once-nonstatic");
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node,
|
||||
bool MultipleInheritanceCheck::isCurrentClassInterface(
|
||||
const CXXRecordDecl *Node) const {
|
||||
// Interfaces should have no fields.
|
||||
if (!Node->field_empty()) return false;
|
||||
if (!Node->field_empty())
|
||||
return false;
|
||||
|
||||
// Interfaces should have exclusively pure methods.
|
||||
return llvm::none_of(Node->methods(), [](const CXXMethodDecl *M) {
|
||||
@@ -68,11 +69,14 @@ bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
|
||||
|
||||
// To be an interface, all base classes must be interfaces as well.
|
||||
for (const auto &I : Node->bases()) {
|
||||
if (I.isVirtual()) continue;
|
||||
if (I.isVirtual())
|
||||
continue;
|
||||
const auto *Ty = I.getType()->getAs<RecordType>();
|
||||
if (!Ty) continue;
|
||||
if (!Ty)
|
||||
continue;
|
||||
const RecordDecl *D = Ty->getDecl()->getDefinition();
|
||||
if (!D) continue;
|
||||
if (!D)
|
||||
continue;
|
||||
const auto *Base = cast<CXXRecordDecl>(D);
|
||||
if (!isInterface(Base)) {
|
||||
addNodeToInterfaceMap(Node, false);
|
||||
@@ -97,20 +101,25 @@ void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
// concrete classes
|
||||
unsigned NumConcrete = 0;
|
||||
for (const auto &I : D->bases()) {
|
||||
if (I.isVirtual()) continue;
|
||||
if (I.isVirtual())
|
||||
continue;
|
||||
const auto *Ty = I.getType()->getAs<RecordType>();
|
||||
if (!Ty) continue;
|
||||
if (!Ty)
|
||||
continue;
|
||||
const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition());
|
||||
if (!isInterface(Base)) NumConcrete++;
|
||||
if (!isInterface(Base))
|
||||
NumConcrete++;
|
||||
}
|
||||
|
||||
// Check virtual bases to see if there is more than one concrete
|
||||
// non-virtual base.
|
||||
for (const auto &V : D->vbases()) {
|
||||
const auto *Ty = V.getType()->getAs<RecordType>();
|
||||
if (!Ty) continue;
|
||||
if (!Ty)
|
||||
continue;
|
||||
const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition());
|
||||
if (!isInterface(Base)) NumConcrete++;
|
||||
if (!isInterface(Base))
|
||||
NumConcrete++;
|
||||
}
|
||||
|
||||
if (NumConcrete > 1) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace clang::tidy::fuchsia {
|
||||
|
||||
/// Constructing global, non-trivial objects with static storage is
|
||||
/// disallowed, unless the object is statically initialized with a constexpr
|
||||
/// disallowed, unless the object is statically initialized with a constexpr
|
||||
/// constructor or has no explicit constructor.
|
||||
///
|
||||
/// For the user-facing documentation see:
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
namespace clang::tidy::fuchsia {
|
||||
|
||||
/// Functions that have trailing returns are disallowed, except for those
|
||||
/// using decltype specifiers and lambda with otherwise unutterable
|
||||
/// Functions that have trailing returns are disallowed, except for those
|
||||
/// using decltype specifiers and lambda with otherwise unutterable
|
||||
/// return types.
|
||||
///
|
||||
/// For the user-facing documentation see:
|
||||
|
||||
@@ -16,10 +16,13 @@ namespace clang::tidy::fuchsia {
|
||||
|
||||
namespace {
|
||||
AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
|
||||
if (!Node.hasDefinition()) return false;
|
||||
if (!Node.getNumVBases()) return false;
|
||||
if (!Node.hasDefinition())
|
||||
return false;
|
||||
if (!Node.getNumVBases())
|
||||
return false;
|
||||
for (const CXXBaseSpecifier &Base : Node.bases())
|
||||
if (Base.isVirtual()) return true;
|
||||
if (Base.isVirtual())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace clang::tidy::fuchsia {
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/virtual-inheritance.html
|
||||
class VirtualInheritanceCheck : public ClangTidyCheck {
|
||||
public:
|
||||
public:
|
||||
VirtualInheritanceCheck(StringRef Name, ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context) {}
|
||||
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
||||
@@ -27,4 +27,4 @@ class VirtualInheritanceCheck : public ClangTidyCheck {
|
||||
|
||||
} // namespace clang::tidy::fuchsia
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
|
||||
|
||||
@@ -120,8 +120,8 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
IsFunction(SourceTypeAsWritten) && IsFunction(DestTypeAsWritten);
|
||||
|
||||
const bool ConstructorCast = !CastExpr->getTypeAsWritten().hasQualifiers() &&
|
||||
DestTypeAsWritten->isRecordType() &&
|
||||
!DestTypeAsWritten->isElaboratedTypeSpecifier();
|
||||
DestTypeAsWritten->isRecordType() &&
|
||||
!DestTypeAsWritten->isElaboratedTypeSpecifier();
|
||||
|
||||
if (CastExpr->getCastKind() == CK_NoOp && !FnToFnCast) {
|
||||
// Function pointer/reference casts may be needed to resolve ambiguities in
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace clang::tidy::google::objc {
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/google/objc-avoid-throwing-exception.html
|
||||
class AvoidThrowingObjCExceptionCheck : public ClangTidyCheck {
|
||||
public:
|
||||
public:
|
||||
AvoidThrowingObjCExceptionCheck(StringRef Name, ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context) {}
|
||||
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
|
||||
@@ -32,4 +32,4 @@ class AvoidThrowingObjCExceptionCheck : public ClangTidyCheck {
|
||||
|
||||
} // namespace clang::tidy::google::objc
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_AVOID_THROWING_EXCEPTION_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_AVOID_THROWING_EXCEPTION_H
|
||||
|
||||
@@ -85,7 +85,7 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
"%0 explicit expression evaluates to 'false'";
|
||||
|
||||
if (const auto *Conversion =
|
||||
Result.Nodes.getNodeAs<CXXConversionDecl>("conversion")) {
|
||||
Result.Nodes.getNodeAs<CXXConversionDecl>("conversion")) {
|
||||
if (Conversion->isOutOfLine())
|
||||
return;
|
||||
SourceLocation Loc = Conversion->getLocation();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//===--- GlobalNamesInHeadersCheck.cpp - clang-tidy -----------------*- C++ -*-===//
|
||||
//===--- GlobalNamesInHeadersCheck.cpp - clang-tidy --------------*- C++-*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
||||
@@ -52,7 +52,7 @@ FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
|
||||
CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
|
||||
llvm::StringRef(NewName));
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
void GlobalVariableDeclarationCheck::registerMatchers(MatchFinder *Finder) {
|
||||
// need to add two matchers since we need to bind different ids to distinguish
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace clang::tidy::google::objc {
|
||||
/// For the user-facing documentation see:
|
||||
/// http://clang.llvm.org/extra/clang-tidy/checks/google/objc-global-variable-declaration.html
|
||||
class GlobalVariableDeclarationCheck : public ClangTidyCheck {
|
||||
public:
|
||||
public:
|
||||
GlobalVariableDeclarationCheck(StringRef Name, ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context) {}
|
||||
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
|
||||
@@ -32,4 +32,4 @@ class GlobalVariableDeclarationCheck : public ClangTidyCheck {
|
||||
|
||||
} // namespace clang::tidy::google::objc
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace clang::tidy {
|
||||
namespace google {
|
||||
|
||||
class GoogleModule : public ClangTidyModule {
|
||||
public:
|
||||
public:
|
||||
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
||||
CheckFactories.registerCheck<build::ExplicitMakePairCheck>(
|
||||
"google-build-explicit-make-pair");
|
||||
@@ -96,7 +96,7 @@ class GoogleModule : public ClangTidyModule {
|
||||
static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
|
||||
"Adds Google lint checks.");
|
||||
|
||||
} // namespace google
|
||||
} // namespace google
|
||||
|
||||
// This anchor is used to force the linker to link in the generated object file
|
||||
// and thus register the GoogleModule.
|
||||
|
||||
@@ -172,8 +172,8 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
// We don't add a fix-it as changing the type can easily break code,
|
||||
// e.g. when a function requires a 'long' argument on all platforms.
|
||||
// QualTypes are printed with implicit quotes.
|
||||
diag(Loc, "consider replacing %0 with '%1'") << BuiltinLoc.getType()
|
||||
<< Replacement;
|
||||
diag(Loc, "consider replacing %0 with '%1'")
|
||||
<< BuiltinLoc.getType() << Replacement;
|
||||
}
|
||||
|
||||
} // namespace tidy::google::runtime
|
||||
|
||||
@@ -21,8 +21,8 @@ UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(
|
||||
|
||||
void UnnamedNamespaceInHeaderCheck::registerMatchers(
|
||||
ast_matchers::MatchFinder *Finder) {
|
||||
Finder->addMatcher(namespaceDecl(isAnonymous()).bind("anonymousNamespace"),
|
||||
this);
|
||||
Finder->addMatcher(namespaceDecl(isAnonymous()).bind("anonymousNamespace"),
|
||||
this);
|
||||
}
|
||||
|
||||
void UnnamedNamespaceInHeaderCheck::check(
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace clang::tidy::google::build {
|
||||
|
||||
void UsingNamespaceDirectiveCheck::registerMatchers(
|
||||
ast_matchers::MatchFinder *Finder) {
|
||||
Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
|
||||
Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
|
||||
}
|
||||
|
||||
void UsingNamespaceDirectiveCheck::check(
|
||||
|
||||
Reference in New Issue
Block a user