Skip to content

Conversation

@localspook
Copy link
Contributor

@localspook localspook commented Dec 19, 2025

Fixing the instances found by misc-use-internal-linkage in #172797.

@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2025

@llvm/pr-subscribers-clang-tidy

Author: Victor Chernyakin (localspook)

Changes

Fixing the instances found in #172797.


Patch is 31.16 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/172947.diff

39 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/ClangTidyOptions.cpp (+8)
  • (modified) clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp (+14-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp (+8-1)
  • (modified) clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/mpi/MPITidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/openmp/OpenMPTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/portability/AvoidPragmaOnceCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/zircon/ZirconTidyModule.cpp (+3)
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 2ebab00b3ed91..aa9525202d4d9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -67,6 +67,8 @@ template <> struct MappingTraits<ClangTidyOptions::StringPair> {
   }
 };
 
+namespace {
+
 struct NOptionMap {
   NOptionMap(IO &) {}
   NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
@@ -84,6 +86,8 @@ struct NOptionMap {
   std::vector<ClangTidyOptions::StringPair> Options;
 };
 
+} // namespace
+
 template <>
 void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
              EmptyContext &Ctx) {
@@ -178,11 +182,15 @@ template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
   }
 };
 
+namespace {
+
 struct GlobListVariant {
   std::optional<std::string> AsString;
   std::optional<std::vector<std::string>> AsVector;
 };
 
+} // namespace
+
 template <>
 void yamlize(IO &IO, GlobListVariant &Val, bool, EmptyContext &Ctx) {
   if (!IO.outputting()) {
diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
index b552ae8b1783a..f428c1d2b3560 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -35,9 +35,13 @@ namespace clang::tidy {
 // NoLintType
 //===----------------------------------------------------------------------===//
 
+namespace {
+
 // The type - one of NOLINT[NEXTLINE/BEGIN/END].
 enum class NoLintType { NoLint, NoLintNextLine, NoLintBegin, NoLintEnd };
 
+} // namespace
+
 // Convert a string like "NOLINTNEXTLINE" to its enum `Type::NoLintNextLine`.
 // Return `std::nullopt` if the string is unrecognized.
 static std::optional<NoLintType> strToNoLintType(StringRef Str) {
diff --git a/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp b/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
index 1083d4373a6bd..e00e88dc76a7f 100644
--- a/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
@@ -32,6 +32,7 @@
 
 namespace clang::tidy {
 namespace abseil {
+namespace {
 
 class AbseilModule : public ClangTidyModule {
 public:
@@ -75,6 +76,8 @@ class AbseilModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the AbseilModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<AbseilModule> X("abseil-module",
                                                     "Add Abseil checks.");
diff --git a/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp b/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
index 28733ef1d994c..c29a3be565332 100644
--- a/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
@@ -19,6 +19,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace altera {
+namespace {
 
 class AlteraModule : public ClangTidyModule {
 public:
@@ -35,6 +36,7 @@ class AlteraModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace altera
 
 // Register the AlteraTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
index 40362531f2daf..6b48ec152838c 100644
--- a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
@@ -29,6 +29,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace android {
+namespace {
 
 /// This module is for Android specific checks.
 class AndroidModule : public ClangTidyModule {
@@ -59,6 +60,8 @@ class AndroidModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the AndroidTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<AndroidModule>
     X("android-module", "Adds Android platform checks.");
diff --git a/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp b/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp
index c13a24401afba..859c25e3366eb 100644
--- a/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp
@@ -15,6 +15,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace boost {
+namespace {
 
 class BoostModule : public ClangTidyModule {
 public:
@@ -24,6 +25,8 @@ class BoostModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the BoostModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<BoostModule> X("boost-module",
                                                    "Add boost checks.");
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 6859dc97c112a..61a680a72a027 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -115,6 +115,7 @@
 
 namespace clang::tidy {
 namespace bugprone {
+namespace {
 
 class BugproneModule : public ClangTidyModule {
 public:
@@ -319,6 +320,7 @@ class BugproneModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace bugprone
 
 // Register the BugproneTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index 496f3e5015990..8047dcea0a5b7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -106,6 +106,8 @@ static bool prefixSuffixCoverUnderThreshold(std::size_t Threshold,
 
 namespace model {
 
+namespace {
+
 /// The language features involved in allowing the mix between two parameters.
 enum class MixFlags : unsigned char {
   Invalid = 0, ///< Sentinel bit pattern. DO NOT USE!
@@ -129,6 +131,9 @@ enum class MixFlags : unsigned char {
 
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue =*/ImplicitConversion)
 };
+
+} // namespace
+
 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
 
 /// Returns whether the SearchedFlag is turned on in the Data.
@@ -179,6 +184,8 @@ static inline std::string formatMixFlags(MixFlags F) {
 
 #endif // NDEBUG
 
+namespace {
+
 /// The results of the steps of an Implicit Conversion Sequence is saved in
 /// an instance of this record.
 ///
@@ -565,6 +572,8 @@ enum class ImplicitConversionModellingMode : unsigned char {
   OneWaySingleStandardOnly
 };
 
+} // namespace
+
 static MixData
 isLRefEquallyBindingToType(const TheCheck &Check,
                            const LValueReferenceType *LRef, QualType Ty,
@@ -1594,6 +1603,8 @@ static bool lazyMapOfSetsIntersectionExists(const MapTy &Map, const ElemTy &E1,
   });
 }
 
+namespace {
+
 /// Implements the heuristic that marks two parameters related if there is
 /// a usage for both in the same strict expression subtree. A strict
 /// expression subtree is a tree which only includes Expr nodes, i.e. no
@@ -1755,6 +1766,8 @@ class Returned {
   }
 };
 
+} // namespace
+
 } // namespace relatedness_heuristic
 
 /// Helper class that is used to detect if two parameters of the same function
@@ -1950,7 +1963,7 @@ static inline bool needsToPrintTypeInDiagnostic(const model::Mix &M) {
 /// Returns whether a particular Mix between the two parameters should have
 /// implicit conversions elaborated.
 static inline bool needsToElaborateImplicitConversion(const model::Mix &M) {
-  return hasFlag(M.flags(), model::MixFlags::ImplicitConversion);
+  return model::hasFlag(M.flags(), model::MixFlags::ImplicitConversion);
 }
 
 namespace {
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 7198c1b1c8aaf..b1c2638bf4829 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -32,11 +32,11 @@ constexpr llvm::StringLiteral LengthExprName = "LengthExpr";
 constexpr llvm::StringLiteral WrongLengthExprName = "WrongLength";
 constexpr llvm::StringLiteral UnknownLengthName = "UnknownLength";
 
+namespace {
 enum class LengthHandleKind { Increase, Decrease };
+} // namespace
 
-namespace {
 static Preprocessor *PP;
-} // namespace
 
 // Returns the expression of destination's capacity which is part of a
 // 'VariableArrayType', 'ConstantArrayTypeLoc' or an argument of a 'malloc()'
diff --git a/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
index 8454fd1045673..701c0e56e6f99 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
@@ -40,6 +40,8 @@ void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) {
       this);
 }
 
+namespace {
+
 class CharExpressionDetector {
 public:
   CharExpressionDetector(QualType CharType, const ASTContext &Ctx)
@@ -124,6 +126,8 @@ class CharExpressionDetector {
   const ASTContext &Ctx;
 };
 
+} // namespace
+
 void StringIntegerAssignmentCheck::check(
     const MatchFinder::MatchResult &Result) {
   const auto *Argument = Result.Nodes.getNodeAs<Expr>("expr");
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
index ef7f0b5b54eb3..f28bdbeb6db84 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
@@ -30,6 +30,8 @@ static const char BitmaskVarErrorMessage[] =
 
 static const char BitmaskNoteMessage[] = "used here as a bitmask";
 
+namespace {
+
 /// Stores a min and a max value which describe an interval.
 struct ValueRange {
   llvm::APSInt MinVal;
@@ -47,6 +49,8 @@ struct ValueRange {
   }
 };
 
+} // namespace
+
 /// Return the number of EnumConstantDecls in an EnumDecl.
 static int enumLength(const EnumDecl *EnumDec) {
   return std::distance(EnumDec->enumerator_begin(), EnumDec->enumerator_end());
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index b2e08fe688a1b..1db56ce54a41e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -397,12 +397,16 @@ void UseAfterMoveFinder::getReinits(
   }
 }
 
+namespace {
+
 enum MoveType {
   Forward = 0,      // std::forward
   Move = 1,         // std::move
   Invalidation = 2, // other
 };
 
+} // namespace
+
 static MoveType determineMoveType(const FunctionDecl *FuncDecl) {
   if (FuncDecl->isInStdNamespace()) {
     if (FuncDecl->getName() == "move")
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index 16d4be9802cc6..2d73e1e7c2e45 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -232,6 +232,7 @@ const llvm::StringRef CertErr33CCheckedFunctions = "^::aligned_alloc$;"
 
 namespace clang::tidy {
 namespace cert {
+namespace {
 
 class CERTModule : public ClangTidyModule {
 public:
@@ -360,6 +361,7 @@ class CERTModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace cert
 
 // Register the MiscTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
index 135a54d4565cb..dc40734fba88d 100644
--- a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
@@ -14,6 +14,7 @@
 
 namespace clang::tidy {
 namespace concurrency {
+namespace {
 
 class ConcurrencyModule : public ClangTidyModule {
 public:
@@ -25,6 +26,7 @@ class ConcurrencyModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace concurrency
 
 // Register the ConcurrencyTidyModule using this statically initialized
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index 66639552276a2..f2d0f5e63172b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -54,6 +54,7 @@
 
 namespace clang::tidy {
 namespace cppcoreguidelines {
+namespace {
 
 /// A module containing checks of the C++ Core Guidelines
 class CppCoreGuidelinesModule : public ClangTidyModule {
@@ -154,6 +155,8 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the LLVMTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
     X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 51a1468f49813..f3e8d66a15102 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -95,11 +95,15 @@ static void updateAssignmentLevel(
   }
 }
 
+namespace {
+
 struct AssignmentPair {
   const FieldDecl *Field;
   const Expr *Init;
 };
 
+} // namespace
+
 static std::optional<AssignmentPair>
 isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
                        const CXXConstructorDecl *Ctor) {
diff --git a/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp b/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp
index 94d76e0dfbb6b..985bb842e4f8a 100644
--- a/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp
@@ -11,15 +11,18 @@
 
 namespace clang::tidy {
 namespace custom {
+namespace {
 
 class CustomModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {}
 };
 
+} // namespace
+
 // We need to register the checks more flexibly than builtin modules. The checks
 // will changed dynamically when switching to different source file.
-extern void registerCustomChecks(const ClangTidyOptions &Options,
+static void registerCustomChecks(const ClangTidyOptions &Options,
                                  ClangTidyCheckFactories &Factories) {
   static llvm::SmallSet<llvm::SmallString<32>, 8> CustomCheckNames{};
   if (!Options.CustomChecks.has_value() || Options.CustomChecks->empty())
@@ -38,12 +41,16 @@ extern void registerCustomChecks(const ClangTidyOptions &Options,
   }
 }
 
+namespace {
+
 struct CustomChecksRegisterInitializer {
   CustomChecksRegisterInitializer() noexcept {
     RegisterCustomChecks = &custom::registerCustomChecks;
   }
 };
 
+} // namespace
+
 static CustomChecksRegisterInitializer Init{};
 
 } // namespace custom
diff --git a/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp b/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
index 0330626a7cd58..9aa236b474513 100644
--- a/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
@@ -14,6 +14,7 @@
 
 namespace clang::tidy {
 namespace darwin {
+namespace {
 
 class DarwinModule : public ClangTidyModule {
 public:
@@ -24,6 +25,7 @@ class DarwinModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace darwin
 
 // Register the DarwinTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
index 284f72a8f20fd..81d067a4d27c8 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -23,6 +23,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace fuchsia {
+namespace {
 
 /// This module is for Fuchsia-specific checks.
 class FuchsiaModule : public ClangTidyModule {
@@ -48,6 +49,9 @@ class FuchsiaModule : public ClangTidyModule {
         "fuchsia-virtual-inheritance");
   }
 };
+
+} // namespace
+
 // Register the FuchsiaTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<FuchsiaModule>
     X("fuchsia-module", "Adds Fuchsia platform checks.");
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index ce46b3f641790..f293182218232 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -34,6 +34,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace google {
+namespace {
 
 class GoogleModule : public ClangTidyModule {
 public:
@@ -95,6 +96,8 @@ class GoogleModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the GoogleTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
                                                     "Adds Google lint checks.");
diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
index 2789e4da320b2..f6a6811af006f 100644
--- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
@@ -14,9 +14,11 @@
 namespace clang::tidy {
 
 namespace google::readability {
+namespace {
 
 enum class StyleKind { Parentheses, Hyphen };
 
+} // namespace
 } // namespace google::readability
 
 template <> struct OptionEnumMapping<google::readability::StyleKind> {
diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 9695eab51062b..9acd293bcf652 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -43,6 +43,7 @@
 
 namespace clang::tidy {
 namespace hicpp {
+namespace {
 
 class HICPPModule : public ClangTidyModule {
 public:
@@ -111,6 +112,8 @@ class HICPPModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the HICPPModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<HICPPModule>
     X("hicpp-module", "Adds High-Integrity C++ checks.");
diff --git a/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp b/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
index 645d07426fee2..b3abc08ac7fc4 100644
--- a/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
@@ -13,6 +13,7 @@
 
 namespace clang::tidy {
 namespace linuxkernel {
+namespace {
 
 /// This module is for checks specific to the Linux kernel.
 class LinuxKernelModule : public ClangTidyModule {
@@ -22,6 +23,9 @@ class LinuxKernelModule : public ClangTidyModule {
         "linuxkernel-must-check-errs");
   }
 };
+
+} // namespace
+
 // Register the LinuxKernelTidyModule using this statically initialized
 // variable.
 static ClangTidyModuleRegistry::Add<LinuxKernelModule>
diff --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
index ed65cd1720457..acc942a125e11 100644
--- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
@@ -23,6 +23,7 @@
 
 namespace clang::tidy {
 namespace llvm_check {
+namespace {
 
 class LLVMModule : public ClangTidyModule {
 public:
@@ -57,6 +58,8 @@ class LLVMModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the LLVMTidyModule using this sta...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Victor Chernyakin (localspook)

Changes

Fixing the instances found in #172797.


Patch is 31.16 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/172947.diff

39 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/ClangTidyOptions.cpp (+8)
  • (modified) clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp (+14-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp (+8-1)
  • (modified) clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/mpi/MPITidyModule.cpp (+2)
  • (modified) clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/openmp/OpenMPTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/portability/AvoidPragmaOnceCheck.cpp (+4)
  • (modified) clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp (+3)
  • (modified) clang-tools-extra/clang-tidy/zircon/ZirconTidyModule.cpp (+3)
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 2ebab00b3ed91..aa9525202d4d9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -67,6 +67,8 @@ template <> struct MappingTraits<ClangTidyOptions::StringPair> {
   }
 };
 
+namespace {
+
 struct NOptionMap {
   NOptionMap(IO &) {}
   NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
@@ -84,6 +86,8 @@ struct NOptionMap {
   std::vector<ClangTidyOptions::StringPair> Options;
 };
 
+} // namespace
+
 template <>
 void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
              EmptyContext &Ctx) {
@@ -178,11 +182,15 @@ template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
   }
 };
 
+namespace {
+
 struct GlobListVariant {
   std::optional<std::string> AsString;
   std::optional<std::vector<std::string>> AsVector;
 };
 
+} // namespace
+
 template <>
 void yamlize(IO &IO, GlobListVariant &Val, bool, EmptyContext &Ctx) {
   if (!IO.outputting()) {
diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
index b552ae8b1783a..f428c1d2b3560 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -35,9 +35,13 @@ namespace clang::tidy {
 // NoLintType
 //===----------------------------------------------------------------------===//
 
+namespace {
+
 // The type - one of NOLINT[NEXTLINE/BEGIN/END].
 enum class NoLintType { NoLint, NoLintNextLine, NoLintBegin, NoLintEnd };
 
+} // namespace
+
 // Convert a string like "NOLINTNEXTLINE" to its enum `Type::NoLintNextLine`.
 // Return `std::nullopt` if the string is unrecognized.
 static std::optional<NoLintType> strToNoLintType(StringRef Str) {
diff --git a/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp b/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
index 1083d4373a6bd..e00e88dc76a7f 100644
--- a/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp
@@ -32,6 +32,7 @@
 
 namespace clang::tidy {
 namespace abseil {
+namespace {
 
 class AbseilModule : public ClangTidyModule {
 public:
@@ -75,6 +76,8 @@ class AbseilModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the AbseilModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<AbseilModule> X("abseil-module",
                                                     "Add Abseil checks.");
diff --git a/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp b/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
index 28733ef1d994c..c29a3be565332 100644
--- a/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
@@ -19,6 +19,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace altera {
+namespace {
 
 class AlteraModule : public ClangTidyModule {
 public:
@@ -35,6 +36,7 @@ class AlteraModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace altera
 
 // Register the AlteraTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
index 40362531f2daf..6b48ec152838c 100644
--- a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
@@ -29,6 +29,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace android {
+namespace {
 
 /// This module is for Android specific checks.
 class AndroidModule : public ClangTidyModule {
@@ -59,6 +60,8 @@ class AndroidModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the AndroidTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<AndroidModule>
     X("android-module", "Adds Android platform checks.");
diff --git a/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp b/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp
index c13a24401afba..859c25e3366eb 100644
--- a/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp
@@ -15,6 +15,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace boost {
+namespace {
 
 class BoostModule : public ClangTidyModule {
 public:
@@ -24,6 +25,8 @@ class BoostModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the BoostModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<BoostModule> X("boost-module",
                                                    "Add boost checks.");
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 6859dc97c112a..61a680a72a027 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -115,6 +115,7 @@
 
 namespace clang::tidy {
 namespace bugprone {
+namespace {
 
 class BugproneModule : public ClangTidyModule {
 public:
@@ -319,6 +320,7 @@ class BugproneModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace bugprone
 
 // Register the BugproneTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index 496f3e5015990..8047dcea0a5b7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -106,6 +106,8 @@ static bool prefixSuffixCoverUnderThreshold(std::size_t Threshold,
 
 namespace model {
 
+namespace {
+
 /// The language features involved in allowing the mix between two parameters.
 enum class MixFlags : unsigned char {
   Invalid = 0, ///< Sentinel bit pattern. DO NOT USE!
@@ -129,6 +131,9 @@ enum class MixFlags : unsigned char {
 
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue =*/ImplicitConversion)
 };
+
+} // namespace
+
 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
 
 /// Returns whether the SearchedFlag is turned on in the Data.
@@ -179,6 +184,8 @@ static inline std::string formatMixFlags(MixFlags F) {
 
 #endif // NDEBUG
 
+namespace {
+
 /// The results of the steps of an Implicit Conversion Sequence is saved in
 /// an instance of this record.
 ///
@@ -565,6 +572,8 @@ enum class ImplicitConversionModellingMode : unsigned char {
   OneWaySingleStandardOnly
 };
 
+} // namespace
+
 static MixData
 isLRefEquallyBindingToType(const TheCheck &Check,
                            const LValueReferenceType *LRef, QualType Ty,
@@ -1594,6 +1603,8 @@ static bool lazyMapOfSetsIntersectionExists(const MapTy &Map, const ElemTy &E1,
   });
 }
 
+namespace {
+
 /// Implements the heuristic that marks two parameters related if there is
 /// a usage for both in the same strict expression subtree. A strict
 /// expression subtree is a tree which only includes Expr nodes, i.e. no
@@ -1755,6 +1766,8 @@ class Returned {
   }
 };
 
+} // namespace
+
 } // namespace relatedness_heuristic
 
 /// Helper class that is used to detect if two parameters of the same function
@@ -1950,7 +1963,7 @@ static inline bool needsToPrintTypeInDiagnostic(const model::Mix &M) {
 /// Returns whether a particular Mix between the two parameters should have
 /// implicit conversions elaborated.
 static inline bool needsToElaborateImplicitConversion(const model::Mix &M) {
-  return hasFlag(M.flags(), model::MixFlags::ImplicitConversion);
+  return model::hasFlag(M.flags(), model::MixFlags::ImplicitConversion);
 }
 
 namespace {
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 7198c1b1c8aaf..b1c2638bf4829 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -32,11 +32,11 @@ constexpr llvm::StringLiteral LengthExprName = "LengthExpr";
 constexpr llvm::StringLiteral WrongLengthExprName = "WrongLength";
 constexpr llvm::StringLiteral UnknownLengthName = "UnknownLength";
 
+namespace {
 enum class LengthHandleKind { Increase, Decrease };
+} // namespace
 
-namespace {
 static Preprocessor *PP;
-} // namespace
 
 // Returns the expression of destination's capacity which is part of a
 // 'VariableArrayType', 'ConstantArrayTypeLoc' or an argument of a 'malloc()'
diff --git a/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
index 8454fd1045673..701c0e56e6f99 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
@@ -40,6 +40,8 @@ void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) {
       this);
 }
 
+namespace {
+
 class CharExpressionDetector {
 public:
   CharExpressionDetector(QualType CharType, const ASTContext &Ctx)
@@ -124,6 +126,8 @@ class CharExpressionDetector {
   const ASTContext &Ctx;
 };
 
+} // namespace
+
 void StringIntegerAssignmentCheck::check(
     const MatchFinder::MatchResult &Result) {
   const auto *Argument = Result.Nodes.getNodeAs<Expr>("expr");
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
index ef7f0b5b54eb3..f28bdbeb6db84 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
@@ -30,6 +30,8 @@ static const char BitmaskVarErrorMessage[] =
 
 static const char BitmaskNoteMessage[] = "used here as a bitmask";
 
+namespace {
+
 /// Stores a min and a max value which describe an interval.
 struct ValueRange {
   llvm::APSInt MinVal;
@@ -47,6 +49,8 @@ struct ValueRange {
   }
 };
 
+} // namespace
+
 /// Return the number of EnumConstantDecls in an EnumDecl.
 static int enumLength(const EnumDecl *EnumDec) {
   return std::distance(EnumDec->enumerator_begin(), EnumDec->enumerator_end());
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index b2e08fe688a1b..1db56ce54a41e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -397,12 +397,16 @@ void UseAfterMoveFinder::getReinits(
   }
 }
 
+namespace {
+
 enum MoveType {
   Forward = 0,      // std::forward
   Move = 1,         // std::move
   Invalidation = 2, // other
 };
 
+} // namespace
+
 static MoveType determineMoveType(const FunctionDecl *FuncDecl) {
   if (FuncDecl->isInStdNamespace()) {
     if (FuncDecl->getName() == "move")
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index 16d4be9802cc6..2d73e1e7c2e45 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -232,6 +232,7 @@ const llvm::StringRef CertErr33CCheckedFunctions = "^::aligned_alloc$;"
 
 namespace clang::tidy {
 namespace cert {
+namespace {
 
 class CERTModule : public ClangTidyModule {
 public:
@@ -360,6 +361,7 @@ class CERTModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace cert
 
 // Register the MiscTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
index 135a54d4565cb..dc40734fba88d 100644
--- a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
@@ -14,6 +14,7 @@
 
 namespace clang::tidy {
 namespace concurrency {
+namespace {
 
 class ConcurrencyModule : public ClangTidyModule {
 public:
@@ -25,6 +26,7 @@ class ConcurrencyModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace concurrency
 
 // Register the ConcurrencyTidyModule using this statically initialized
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index 66639552276a2..f2d0f5e63172b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -54,6 +54,7 @@
 
 namespace clang::tidy {
 namespace cppcoreguidelines {
+namespace {
 
 /// A module containing checks of the C++ Core Guidelines
 class CppCoreGuidelinesModule : public ClangTidyModule {
@@ -154,6 +155,8 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the LLVMTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule>
     X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines.");
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 51a1468f49813..f3e8d66a15102 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -95,11 +95,15 @@ static void updateAssignmentLevel(
   }
 }
 
+namespace {
+
 struct AssignmentPair {
   const FieldDecl *Field;
   const Expr *Init;
 };
 
+} // namespace
+
 static std::optional<AssignmentPair>
 isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
                        const CXXConstructorDecl *Ctor) {
diff --git a/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp b/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp
index 94d76e0dfbb6b..985bb842e4f8a 100644
--- a/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp
@@ -11,15 +11,18 @@
 
 namespace clang::tidy {
 namespace custom {
+namespace {
 
 class CustomModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {}
 };
 
+} // namespace
+
 // We need to register the checks more flexibly than builtin modules. The checks
 // will changed dynamically when switching to different source file.
-extern void registerCustomChecks(const ClangTidyOptions &Options,
+static void registerCustomChecks(const ClangTidyOptions &Options,
                                  ClangTidyCheckFactories &Factories) {
   static llvm::SmallSet<llvm::SmallString<32>, 8> CustomCheckNames{};
   if (!Options.CustomChecks.has_value() || Options.CustomChecks->empty())
@@ -38,12 +41,16 @@ extern void registerCustomChecks(const ClangTidyOptions &Options,
   }
 }
 
+namespace {
+
 struct CustomChecksRegisterInitializer {
   CustomChecksRegisterInitializer() noexcept {
     RegisterCustomChecks = &custom::registerCustomChecks;
   }
 };
 
+} // namespace
+
 static CustomChecksRegisterInitializer Init{};
 
 } // namespace custom
diff --git a/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp b/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
index 0330626a7cd58..9aa236b474513 100644
--- a/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
@@ -14,6 +14,7 @@
 
 namespace clang::tidy {
 namespace darwin {
+namespace {
 
 class DarwinModule : public ClangTidyModule {
 public:
@@ -24,6 +25,7 @@ class DarwinModule : public ClangTidyModule {
   }
 };
 
+} // namespace
 } // namespace darwin
 
 // Register the DarwinTidyModule using this statically initialized variable.
diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
index 284f72a8f20fd..81d067a4d27c8 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -23,6 +23,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace fuchsia {
+namespace {
 
 /// This module is for Fuchsia-specific checks.
 class FuchsiaModule : public ClangTidyModule {
@@ -48,6 +49,9 @@ class FuchsiaModule : public ClangTidyModule {
         "fuchsia-virtual-inheritance");
   }
 };
+
+} // namespace
+
 // Register the FuchsiaTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<FuchsiaModule>
     X("fuchsia-module", "Adds Fuchsia platform checks.");
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index ce46b3f641790..f293182218232 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -34,6 +34,7 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy {
 namespace google {
+namespace {
 
 class GoogleModule : public ClangTidyModule {
 public:
@@ -95,6 +96,8 @@ class GoogleModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the GoogleTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
                                                     "Adds Google lint checks.");
diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
index 2789e4da320b2..f6a6811af006f 100644
--- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
@@ -14,9 +14,11 @@
 namespace clang::tidy {
 
 namespace google::readability {
+namespace {
 
 enum class StyleKind { Parentheses, Hyphen };
 
+} // namespace
 } // namespace google::readability
 
 template <> struct OptionEnumMapping<google::readability::StyleKind> {
diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 9695eab51062b..9acd293bcf652 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -43,6 +43,7 @@
 
 namespace clang::tidy {
 namespace hicpp {
+namespace {
 
 class HICPPModule : public ClangTidyModule {
 public:
@@ -111,6 +112,8 @@ class HICPPModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the HICPPModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add<HICPPModule>
     X("hicpp-module", "Adds High-Integrity C++ checks.");
diff --git a/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp b/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
index 645d07426fee2..b3abc08ac7fc4 100644
--- a/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
@@ -13,6 +13,7 @@
 
 namespace clang::tidy {
 namespace linuxkernel {
+namespace {
 
 /// This module is for checks specific to the Linux kernel.
 class LinuxKernelModule : public ClangTidyModule {
@@ -22,6 +23,9 @@ class LinuxKernelModule : public ClangTidyModule {
         "linuxkernel-must-check-errs");
   }
 };
+
+} // namespace
+
 // Register the LinuxKernelTidyModule using this statically initialized
 // variable.
 static ClangTidyModuleRegistry::Add<LinuxKernelModule>
diff --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
index ed65cd1720457..acc942a125e11 100644
--- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
@@ -23,6 +23,7 @@
 
 namespace clang::tidy {
 namespace llvm_check {
+namespace {
 
 class LLVMModule : public ClangTidyModule {
 public:
@@ -57,6 +58,8 @@ class LLVMModule : public ClangTidyModule {
   }
 };
 
+} // namespace
+
 // Register the LLVMTidyModule using this sta...
[truncated]

// We need to register the checks more flexibly than builtin modules. The checks
// will changed dynamically when switching to different source file.
extern void registerCustomChecks(const ClangTidyOptions &Options,
static void registerCustomChecks(const ClangTidyOptions &Options,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drive-by fix.

@localspook localspook enabled auto-merge (squash) December 19, 2025 16:40
@localspook localspook merged commit 9cd8018 into llvm:main Dec 19, 2025
11 checks passed
@localspook localspook deleted the clang-tidy-use-internal-linkage branch December 19, 2025 16:51
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 19, 2025

LLVM Buildbot has detected a new failure on builder clang-m68k-linux-cross running on suse-gary-m68k-cross while building clang-tools-extra at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/20571

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clang :: Preprocessor/c99-6_10_3_4_p6.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 3
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/bin/clang -cc1 -internal-isystem /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/lib/clang/22/include -nostdsysteminc -E /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c | /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/bin/FileCheck -strict-whitespace /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c
# executed command: /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/bin/clang -cc1 -internal-isystem /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/lib/clang/22/include -nostdsysteminc -E /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c
# .---command stderr------------
# | /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c:7:57: warning: backslash and newline separated by space [-Wbackslash-newline-escape]
# |     7 | #define debug(s, t) printf("x" # s "= %d, x" # t "= s" \ 
# |       |                                                         ^
# | 1 warning generated.
# `-----------------------------
# executed command: /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/bin/FileCheck -strict-whitespace /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c
# .---command stderr------------
# | /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c:24:11: error: CHECK: expected string not found in input
# | // CHECK: include "vers2.h"
# |           ^
# | <stdin>:10:62: note: scanning from here
# | fputs("strncmp(\"abc\\0d\" \"abc\", '\\4') == 0" ": @\n", s);
# |                                                              ^
# | <stdin>:12:1: note: possible intended match here
# | include "vers2 .h"
# | ^
# | 
# | Input file: <stdin>
# | Check file: /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |             5: # 1 "<command line>" 1 
# |             6: # 1 "<built-in>" 2 
# |             7: # 1 "/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c" 2 
# |             8: # 14 "/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/Preprocessor/c99-6_10_3_4_p6.c" 
# |             9: printf("x" "1" "= %d, x" "2" "= s" x1, x2); 
# |            10: fputs("strncmp(\"abc\\0d\" \"abc\", '\\4') == 0" ": @\n", s); 
# | check:24'0                                                                  X error: no match found
# |            11:  
# | check:24'0     ~
# |            12: include "vers2 .h" 
# | check:24'0     ~~~~~~~~~~~~~~~~~~~
# | check:24'1     ?                   possible intended match
# |            13: "hello"; 
# | check:24'0     ~~~~~~~~~
...

mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Dec 19, 2025
…here applicable (llvm#172947)

Fixing the instances found by `misc-use-internal-linkage` in llvm#172797.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants