From e611d88083e9ea0bb0e7dd6371b19587e745ccae Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Sun, 26 Oct 2025 23:56:03 +0300 Subject: [PATCH 1/3] [clang-tidy][NFC] Fix llvm-prefer-static-over-anonymous-namespace warnings N/N --- .../InvalidEnumDefaultInitializationCheck.cpp | 1 + .../bugprone/SmartPtrArrayMismatchCheck.cpp | 14 ++--- .../clang-tidy/google/FunctionNamingCheck.cpp | 8 +-- .../misc/UseInternalLinkageCheck.cpp | 12 ++-- .../modernize/AvoidCArraysCheck.cpp | 16 +++--- .../clang-tidy/modernize/UseAutoCheck.cpp | 55 +++++++++---------- .../UseDesignatedInitializersCheck.cpp | 12 ++-- .../clang-tidy/modernize/UseEmplaceCheck.cpp | 22 ++++---- .../ImplicitBoolConversionCheck.cpp | 1 + .../clang-tidy/utils/ExceptionAnalyzer.cpp | 18 +++--- 10 files changed, 75 insertions(+), 84 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp index 76df992f29fc1..9c79431057aa8 100644 --- a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp @@ -20,6 +20,7 @@ namespace clang::tidy::bugprone { namespace { +// NOLINTNEXTLINE(llvm-prefer-static-over-anonymous-namespace) bool isCompleteAndHasNoZeroValue(const EnumDecl *D) { const EnumDecl *Definition = D->getDefinition(); return Definition && Definition->isComplete() && diff --git a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp index ee797ecb694bd..98b0fb839c08a 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp @@ -15,13 +15,11 @@ using namespace clang::ast_matchers; namespace clang::tidy::bugprone { -namespace { +static constexpr char ConstructExprN[] = "found_construct_expr"; +static constexpr char NewExprN[] = "found_new_expr"; +static constexpr char ConstructorN[] = "found_constructor"; -constexpr char ConstructExprN[] = "found_construct_expr"; -constexpr char NewExprN[] = "found_new_expr"; -constexpr char ConstructorN[] = "found_constructor"; - -bool isInSingleDeclStmt(const DeclaratorDecl *D) { +static bool isInSingleDeclStmt(const DeclaratorDecl *D) { const DynTypedNodeList Parents = D->getASTContext().getParentMapContext().getParents(*D); for (const DynTypedNode &PNode : Parents) @@ -30,7 +28,7 @@ bool isInSingleDeclStmt(const DeclaratorDecl *D) { return false; } -const DeclaratorDecl *getConstructedVarOrField(const Expr *FoundConstructExpr, +static const DeclaratorDecl *getConstructedVarOrField(const Expr *FoundConstructExpr, ASTContext &Ctx) { const DynTypedNodeList ConstructParents = Ctx.getParentMapContext().getParents(*FoundConstructExpr); @@ -43,8 +41,6 @@ const DeclaratorDecl *getConstructedVarOrField(const Expr *FoundConstructExpr, return nullptr; } -} // namespace - const char SmartPtrArrayMismatchCheck::PointerTypeN[] = "pointer_type"; SmartPtrArrayMismatchCheck::SmartPtrArrayMismatchCheck( diff --git a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp index 3d75f4dd25bd1..ce0e4e6896f37 100644 --- a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.cpp @@ -14,9 +14,7 @@ using namespace clang::ast_matchers; namespace clang::tidy::google::objc { -namespace { - -std::string validFunctionNameRegex(bool RequirePrefix) { +static std::string validFunctionNameRegex(bool RequirePrefix) { // Allow the following name patterns for all functions: // • ABFoo (prefix + UpperCamelCase) // • ABURL (prefix + capitalized acronym/initialism) @@ -43,7 +41,7 @@ std::string validFunctionNameRegex(bool RequirePrefix) { /// For now we will only fix functions of static storage class with names like /// 'functionName' or 'function_name' and convert them to 'FunctionName'. For /// other cases the user must determine an appropriate name on their own. -FixItHint generateFixItHint(const FunctionDecl *Decl) { +static FixItHint generateFixItHint(const FunctionDecl *Decl) { // A fixit can be generated for functions of static storage class but // otherwise the check cannot determine the appropriate function name prefix // to use. @@ -82,8 +80,6 @@ FixItHint generateFixItHint(const FunctionDecl *Decl) { return {}; } -} // namespace - void FunctionNamingCheck::registerMatchers(MatchFinder *Finder) { // Enforce Objective-C function naming conventions on all functions except: // • Functions defined in system headers. diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp index 415852d6f14e9..1d2706499dab5 100644 --- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp @@ -43,12 +43,6 @@ struct OptionEnumMapping { namespace clang::tidy::misc { -namespace { - -AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); } - -AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); } - static bool isInMainFile(SourceLocation L, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions) { for (;;) { @@ -65,6 +59,12 @@ static bool isInMainFile(SourceLocation L, SourceManager &SM, } } +namespace { + +AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); } + +AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); } + AST_MATCHER_P(Decl, isAllRedeclsInMainFile, FileExtensionsSet, HeaderFileExtensions) { return llvm::all_of(Node.redecls(), [&](const Decl *D) { diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp index 92900192957e5..71d89d3ab6098 100644 --- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp @@ -15,6 +15,14 @@ using namespace clang::ast_matchers; namespace clang::tidy::modernize { +template +static const TargetType *getAs(const NodeType *Node) { + if constexpr (std::is_same_v) + return Node->template get(); + else + return llvm::dyn_cast(Node); +} + namespace { AST_MATCHER(clang::TypeLoc, hasValidBeginLoc) { @@ -39,14 +47,6 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) { return FD ? FD->isMain() : false; } -template -const TargetType *getAs(const NodeType *Node) { - if constexpr (std::is_same_v) - return Node->template get(); - else - return llvm::dyn_cast(Node); -} - AST_MATCHER(clang::TypeLoc, isWithinImplicitTemplateInstantiation) { const auto IsImplicitTemplateInstantiation = [](const auto *Node) { const auto IsImplicitInstantiation = [](const auto *Node) { diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp index 01796a6f4af2d..084349be7b609 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp @@ -20,14 +20,13 @@ using namespace clang::ast_matchers; using namespace clang::ast_matchers::internal; namespace clang::tidy::modernize { -namespace { -const char IteratorDeclStmtId[] = "iterator_decl"; -const char DeclWithNewId[] = "decl_new"; -const char DeclWithCastId[] = "decl_cast"; -const char DeclWithTemplateCastId[] = "decl_template"; +static const char IteratorDeclStmtId[] = "iterator_decl"; +static const char DeclWithNewId[] = "decl_new"; +static const char DeclWithCastId[] = "decl_cast"; +static const char DeclWithTemplateCastId[] = "decl_template"; -size_t getTypeNameLength(bool RemoveStars, StringRef Text) { +static size_t getTypeNameLength(bool RemoveStars, StringRef Text) { enum CharType { Space, Alpha, Punctuation }; CharType LastChar = Space, BeforeSpace = Punctuation; size_t NumChars = 0; @@ -54,6 +53,7 @@ size_t getTypeNameLength(bool RemoveStars, StringRef Text) { return NumChars; } +namespace { /// Matches variable declarations that have explicit initializers that /// are not initializer lists. /// @@ -65,7 +65,7 @@ size_t getTypeNameLength(bool RemoveStars, StringRef Text) { /// MyType C; /// \endcode /// -/// varDecl(hasWrittenNonListInitializer()) maches \c I and \c A but not \c B +/// varDecl(hasWrittenNonListInitializer()) matches \c I and \c A but not \c B /// or \c C. AST_MATCHER(VarDecl, hasWrittenNonListInitializer) { const Expr *Init = Node.getAnyInitializer(); @@ -108,6 +108,15 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher, SugarMatcher) { } } +/// Matches declaration reference or member expressions with explicit template +/// arguments. +AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs, + AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr, + MemberExpr)) { + return Node.hasExplicitTemplateArgs(); +} +} // namespace + /// Matches named declarations that have one of the standard iterator /// names: iterator, reverse_iterator, const_iterator, const_reverse_iterator. /// @@ -118,7 +127,7 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher, SugarMatcher) { /// \endcode /// /// namedDecl(hasStdIteratorName()) matches \c I and \c CI. -Matcher hasStdIteratorName() { +static Matcher hasStdIteratorName() { static const StringRef IteratorNames[] = {"iterator", "reverse_iterator", "const_iterator", "const_reverse_iterator"}; @@ -137,7 +146,7 @@ Matcher hasStdIteratorName() { /// /// recordDecl(hasStdContainerName()) matches \c vector and \c forward_list /// but not \c my_vec. -Matcher hasStdContainerName() { +static Matcher hasStdContainerName() { static StringRef ContainerNames[] = {"array", "deque", "forward_list", "list", "vector", @@ -154,17 +163,9 @@ Matcher hasStdContainerName() { return hasAnyName(ContainerNames); } -/// Matches declaration reference or member expressions with explicit template -/// arguments. -AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs, - AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr, - MemberExpr)) { - return Node.hasExplicitTemplateArgs(); -} - /// Returns a DeclarationMatcher that matches standard iterators nested /// inside records with a standard container name. -DeclarationMatcher standardIterator() { +static DeclarationMatcher standardIterator() { return decl( namedDecl(hasStdIteratorName()), hasDeclContext(recordDecl(hasStdContainerName(), isInStdNamespace()))); @@ -172,19 +173,19 @@ DeclarationMatcher standardIterator() { /// Returns a TypeMatcher that matches typedefs for standard iterators /// inside records with a standard container name. -TypeMatcher typedefIterator() { +static TypeMatcher typedefIterator() { return typedefType(hasDeclaration(standardIterator())); } /// Returns a TypeMatcher that matches records named for standard /// iterators nested inside records named for standard containers. -TypeMatcher nestedIterator() { +static TypeMatcher nestedIterator() { return recordType(hasDeclaration(standardIterator())); } /// Returns a TypeMatcher that matches types declared with using /// declarations and which name standard iterators for standard containers. -TypeMatcher iteratorFromUsingDeclaration() { +static TypeMatcher iteratorFromUsingDeclaration() { auto HasIteratorDecl = hasDeclaration(namedDecl(hasStdIteratorName())); // Unwrap the nested name specifier to test for one of the standard // containers. @@ -198,7 +199,7 @@ TypeMatcher iteratorFromUsingDeclaration() { /// This matcher returns declaration statements that contain variable /// declarations with written non-list initializer for standard iterators. -StatementMatcher makeIteratorDeclMatcher() { +static StatementMatcher makeIteratorDeclMatcher() { return declStmt(unless(has( varDecl(anyOf(unless(hasWrittenNonListInitializer()), unless(hasType(isSugarFor(anyOf( @@ -207,7 +208,7 @@ StatementMatcher makeIteratorDeclMatcher() { .bind(IteratorDeclStmtId); } -StatementMatcher makeDeclWithNewMatcher() { +static StatementMatcher makeDeclWithNewMatcher() { return declStmt( unless(has(varDecl(anyOf( unless(hasInitializer(ignoringParenImpCasts(cxxNewExpr()))), @@ -225,13 +226,13 @@ StatementMatcher makeDeclWithNewMatcher() { .bind(DeclWithNewId); } -StatementMatcher makeDeclWithCastMatcher() { +static StatementMatcher makeDeclWithCastMatcher() { return declStmt( unless(has(varDecl(unless(hasInitializer(explicitCastExpr())))))) .bind(DeclWithCastId); } -StatementMatcher makeDeclWithTemplateCastMatcher() { +static StatementMatcher makeDeclWithTemplateCastMatcher() { auto ST = substTemplateTypeParmType(hasReplacementType(equalsBoundNode("arg"))); @@ -252,7 +253,7 @@ StatementMatcher makeDeclWithTemplateCastMatcher() { .bind(DeclWithTemplateCastId); } -StatementMatcher makeCombinedMatcher() { +static StatementMatcher makeCombinedMatcher() { return declStmt( // At least one varDecl should be a child of the declStmt to ensure // it's a declaration list and avoid matching other declarations, @@ -265,8 +266,6 @@ StatementMatcher makeCombinedMatcher() { makeDeclWithCastMatcher(), makeDeclWithTemplateCastMatcher())); } -} // namespace - UseAutoCheck::UseAutoCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), MinTypeNameLength(Options.get("MinTypeNameLength", 5)), diff --git a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp index cc7c2d1e1dff5..c1094b1fc194a 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp @@ -40,6 +40,12 @@ static constexpr char StrictCppStandardComplianceName[] = "StrictCppStandardCompliance"; static constexpr bool StrictCppStandardComplianceDefault = true; +static unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) { + return llvm::count_if(*SyntacticInitList, [](auto *InitExpr) { + return isa(InitExpr); + }); +} + namespace { struct Designators { @@ -74,12 +80,6 @@ struct Designators { } }; -unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) { - return llvm::count_if(*SyntacticInitList, [](auto *InitExpr) { - return isa(InitExpr); - }); -} - AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.hasDefinition() && Node.isAggregate(); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp index ade0085267db3..c5a28ed4e4073 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp @@ -81,41 +81,42 @@ AST_MATCHER(CXXMemberCallExpr, hasSameNumArgsAsDeclNumParams) { AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) { return Node.hasExplicitTemplateArgs(); } +} // namespace // Helper Matcher which applies the given QualType Matcher either directly or by // resolving a pointer type to its pointee. Used to match v.push_back() as well // as p->push_back(). -auto hasTypeOrPointeeType( +static auto hasTypeOrPointeeType( const ast_matchers::internal::Matcher &TypeMatcher) { return anyOf(hasType(TypeMatcher), hasType(pointerType(pointee(TypeMatcher)))); } // Matches if the node has canonical type matching any of the given names. -auto hasWantedType(llvm::ArrayRef TypeNames) { +static auto hasWantedType(llvm::ArrayRef TypeNames) { return hasCanonicalType(hasDeclaration(cxxRecordDecl(hasAnyName(TypeNames)))); } // Matches member call expressions of the named method on the listed container // types. -auto cxxMemberCallExprOnContainer(StringRef MethodName, +static auto cxxMemberCallExprOnContainer(StringRef MethodName, llvm::ArrayRef ContainerNames) { return cxxMemberCallExpr( hasDeclaration(functionDecl(hasName(MethodName))), on(hasTypeOrPointeeType(hasWantedType(ContainerNames)))); } -const auto DefaultContainersWithPushBack = +static const auto DefaultContainersWithPushBack = "::std::vector; ::std::list; ::std::deque"; -const auto DefaultContainersWithPush = +static const auto DefaultContainersWithPush = "::std::stack; ::std::queue; ::std::priority_queue"; -const auto DefaultContainersWithPushFront = +static const auto DefaultContainersWithPushFront = "::std::forward_list; ::std::list; ::std::deque"; -const auto DefaultSmartPointers = +static const auto DefaultSmartPointers = "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr"; -const auto DefaultTupleTypes = "::std::pair; ::std::tuple"; -const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple"; -const auto DefaultEmplacyFunctions = +static const auto DefaultTupleTypes = "::std::pair; ::std::tuple"; +static const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple"; +static const auto DefaultEmplacyFunctions = "vector::emplace_back; vector::emplace;" "deque::emplace; deque::emplace_front; deque::emplace_back;" "forward_list::emplace_after; forward_list::emplace_front;" @@ -129,7 +130,6 @@ const auto DefaultEmplacyFunctions = "unordered_multiset::emplace; unordered_multiset::emplace_hint;" "unordered_multimap::emplace; unordered_multimap::emplace_hint;" "stack::emplace; queue::emplace; priority_queue::emplace"; -} // namespace UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), IgnoreImplicitConstructors(Options.get( diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index 6f6da57d7822b..bc31a3470683c 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -29,6 +29,7 @@ AST_MATCHER(Stmt, isMacroExpansion) { AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; } +// NOLINTNEXTLINE(llvm-prefer-static-over-anonymous-namespace) bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) { SourceManager &SM = Context.getSourceManager(); const LangOptions &LO = Context.getLangOpts(); diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp index fd4320eb8144b..185d2b90198b7 100644 --- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp @@ -44,9 +44,8 @@ ExceptionAnalyzer::ExceptionInfo &ExceptionAnalyzer::ExceptionInfo::merge( } // FIXME: This could be ported to clang later. -namespace { -bool isUnambiguousPublicBaseClass(const Type *DerivedType, +static bool isUnambiguousPublicBaseClass(const Type *DerivedType, const Type *BaseType) { const auto *DerivedClass = DerivedType->getCanonicalTypeUnqualified()->getAsCXXRecordDecl(); @@ -78,11 +77,11 @@ bool isUnambiguousPublicBaseClass(const Type *DerivedType, IsPublicBaseClass; } -inline bool isPointerOrPointerToMember(const Type *T) { +static bool isPointerOrPointerToMember(const Type *T) { return T->isPointerType() || T->isMemberPointerType(); } -std::optional getPointeeOrArrayElementQualType(QualType T) { +static std::optional getPointeeOrArrayElementQualType(QualType T) { if (T->isAnyPointerType() || T->isMemberPointerType()) return T->getPointeeType(); @@ -92,7 +91,7 @@ std::optional getPointeeOrArrayElementQualType(QualType T) { return std::nullopt; } -bool isBaseOf(const Type *DerivedType, const Type *BaseType) { +static bool isBaseOf(const Type *DerivedType, const Type *BaseType) { const auto *DerivedClass = DerivedType->getAsCXXRecordDecl(); const auto *BaseClass = BaseType->getAsCXXRecordDecl(); if (!DerivedClass || !BaseClass) @@ -103,12 +102,12 @@ bool isBaseOf(const Type *DerivedType, const Type *BaseType) { } // Check if T1 is more or Equally qualified than T2. -bool moreOrEquallyQualified(QualType T1, QualType T2) { +static bool moreOrEquallyQualified(QualType T1, QualType T2) { return T1.getQualifiers().isStrictSupersetOf(T2.getQualifiers()) || T1.getQualifiers() == T2.getQualifiers(); } -bool isStandardPointerConvertible(QualType From, QualType To) { +static bool isStandardPointerConvertible(QualType From, QualType To) { assert((From->isPointerType() || From->isMemberPointerType()) && (To->isPointerType() || To->isMemberPointerType()) && "Pointer conversion should be performed on pointer types only."); @@ -150,7 +149,7 @@ bool isStandardPointerConvertible(QualType From, QualType To) { return false; } -bool isFunctionPointerConvertible(QualType From, QualType To) { +static bool isFunctionPointerConvertible(QualType From, QualType To) { if (!From->isFunctionPointerType() && !From->isFunctionType() && !From->isMemberFunctionPointerType()) return false; @@ -192,7 +191,7 @@ bool isFunctionPointerConvertible(QualType From, QualType To) { // from the C rules. // // The function should only be called in C++ mode. -bool isQualificationConvertiblePointer(QualType From, QualType To, +static bool isQualificationConvertiblePointer(QualType From, QualType To, LangOptions LangOpts) { // [N4659 7.5 (1)] @@ -320,7 +319,6 @@ bool isQualificationConvertiblePointer(QualType From, QualType To, return From.getTypePtr() == To.getTypePtr(); } -} // namespace static bool canThrow(const FunctionDecl *Func) { // consteval specifies that every call to the function must produce a From 38f3ce5d98d9aacca34953ce7f4bd1299377ec17 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 27 Oct 2025 00:00:32 +0300 Subject: [PATCH 2/3] run clang-format --- .../clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp | 4 ++-- .../clang-tidy/modernize/UseEmplaceCheck.cpp | 8 +++++--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp index 98b0fb839c08a..f76e4a722a508 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp @@ -28,8 +28,8 @@ static bool isInSingleDeclStmt(const DeclaratorDecl *D) { return false; } -static const DeclaratorDecl *getConstructedVarOrField(const Expr *FoundConstructExpr, - ASTContext &Ctx) { +static const DeclaratorDecl * +getConstructedVarOrField(const Expr *FoundConstructExpr, ASTContext &Ctx) { const DynTypedNodeList ConstructParents = Ctx.getParentMapContext().getParents(*FoundConstructExpr); if (ConstructParents.size() != 1) diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp index c5a28ed4e4073..e585dd1d40002 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp @@ -99,8 +99,9 @@ static auto hasWantedType(llvm::ArrayRef TypeNames) { // Matches member call expressions of the named method on the listed container // types. -static auto cxxMemberCallExprOnContainer(StringRef MethodName, - llvm::ArrayRef ContainerNames) { +static auto +cxxMemberCallExprOnContainer(StringRef MethodName, + llvm::ArrayRef ContainerNames) { return cxxMemberCallExpr( hasDeclaration(functionDecl(hasName(MethodName))), on(hasTypeOrPointeeType(hasWantedType(ContainerNames)))); @@ -115,7 +116,8 @@ static const auto DefaultContainersWithPushFront = static const auto DefaultSmartPointers = "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr"; static const auto DefaultTupleTypes = "::std::pair; ::std::tuple"; -static const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple"; +static const auto DefaultTupleMakeFunctions = + "::std::make_pair; ::std::make_tuple"; static const auto DefaultEmplacyFunctions = "vector::emplace_back; vector::emplace;" "deque::emplace; deque::emplace_front; deque::emplace_back;" diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp index 185d2b90198b7..706dd67c16776 100644 --- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp @@ -46,7 +46,7 @@ ExceptionAnalyzer::ExceptionInfo &ExceptionAnalyzer::ExceptionInfo::merge( // FIXME: This could be ported to clang later. static bool isUnambiguousPublicBaseClass(const Type *DerivedType, - const Type *BaseType) { + const Type *BaseType) { const auto *DerivedClass = DerivedType->getCanonicalTypeUnqualified()->getAsCXXRecordDecl(); const auto *BaseClass = @@ -192,7 +192,7 @@ static bool isFunctionPointerConvertible(QualType From, QualType To) { // // The function should only be called in C++ mode. static bool isQualificationConvertiblePointer(QualType From, QualType To, - LangOptions LangOpts) { + LangOptions LangOpts) { // [N4659 7.5 (1)] // A cv-decomposition of a type T is a sequence of cv_i and P_i such that T is From a6fd8ad217b1e393abc1e108704f4e8000065f57 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 31 Oct 2025 01:17:21 +0300 Subject: [PATCH 3/3] add comments on nolint --- .../bugprone/InvalidEnumDefaultInitializationCheck.cpp | 1 + .../clang-tidy/readability/ImplicitBoolConversionCheck.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp index 9c79431057aa8..18eb40f4eb6d2 100644 --- a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp @@ -20,6 +20,7 @@ namespace clang::tidy::bugprone { namespace { +// Preserve same name as AST_MATCHER(isCompleteAndHasNoZeroValue) // NOLINTNEXTLINE(llvm-prefer-static-over-anonymous-namespace) bool isCompleteAndHasNoZeroValue(const EnumDecl *D) { const EnumDecl *Definition = D->getDefinition(); diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index bc31a3470683c..4cf8574e56c5e 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -29,6 +29,7 @@ AST_MATCHER(Stmt, isMacroExpansion) { AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; } +// Preserve same name as AST_MATCHER(isNULLMacroExpansion) // NOLINTNEXTLINE(llvm-prefer-static-over-anonymous-namespace) bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) { SourceManager &SM = Context.getSourceManager();