Skip to content

[clang-tidy][NFC] run clang-format over 'cert', 'cppcore', 'fuchsia',… #143316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ class CERTModule : public ClangTidyModule {
"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
Expand All @@ -278,8 +277,7 @@ class CERTModule : public ClangTidyModule {
"cert-oop54-cpp");
CheckFactories.registerCheck<NonTrivialTypesLibcMemoryCallsCheck>(
"cert-oop57-cpp");
CheckFactories.registerCheck<MutatingCopyCheck>(
"cert-oop58-cpp");
CheckFactories.registerCheck<MutatingCopyCheck>("cert-oop58-cpp");

// C checkers
// ARR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/darwin/AvoidSpinlockCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
3 changes: 1 addition & 2 deletions clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
27 changes: 18 additions & 9 deletions clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading