Skip to content

Commit 9cd8018

Browse files
authored
[clang-tidy][NFC] Give structs, classes, and enums internal linkage where applicable (#172947)
Fixing the instances found by `misc-use-internal-linkage` in #172797.
1 parent 3c685e4 commit 9cd8018

39 files changed

+139
-10
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ template <> struct MappingTraits<ClangTidyOptions::StringPair> {
6666
}
6767
};
6868

69+
namespace {
70+
6971
struct NOptionMap {
7072
NOptionMap(IO &) {}
7173
NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
@@ -83,6 +85,8 @@ struct NOptionMap {
8385
std::vector<ClangTidyOptions::StringPair> Options;
8486
};
8587

88+
} // namespace
89+
8690
template <>
8791
void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
8892
EmptyContext &Ctx) {
@@ -176,11 +180,15 @@ template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
176180
}
177181
};
178182

183+
namespace {
184+
179185
struct GlobListVariant {
180186
std::optional<std::string> AsString;
181187
std::optional<std::vector<std::string>> AsVector;
182188
};
183189

190+
} // namespace
191+
184192
template <>
185193
void yamlize(IO &IO, GlobListVariant &Val, bool, EmptyContext &Ctx) {
186194
if (!IO.outputting()) {

clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ namespace clang::tidy {
3535
// NoLintType
3636
//===----------------------------------------------------------------------===//
3737

38+
namespace {
39+
3840
// The type - one of NOLINT[NEXTLINE/BEGIN/END].
3941
enum class NoLintType { NoLint, NoLintNextLine, NoLintBegin, NoLintEnd };
4042

43+
} // namespace
44+
4145
// Convert a string like "NOLINTNEXTLINE" to its enum `Type::NoLintNextLine`.
4246
// Return `std::nullopt` if the string is unrecognized.
4347
static std::optional<NoLintType> strToNoLintType(StringRef Str) {

clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
namespace clang::tidy {
3434
namespace abseil {
35+
namespace {
3536

3637
class AbseilModule : public ClangTidyModule {
3738
public:
@@ -75,6 +76,8 @@ class AbseilModule : public ClangTidyModule {
7576
}
7677
};
7778

79+
} // namespace
80+
7881
// Register the AbseilModule using this statically initialized variable.
7982
static ClangTidyModuleRegistry::Add<AbseilModule> X("abseil-module",
8083
"Add Abseil checks.");

clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using namespace clang::ast_matchers;
1919

2020
namespace clang::tidy {
2121
namespace altera {
22+
namespace {
2223

2324
class AlteraModule : public ClangTidyModule {
2425
public:
@@ -35,6 +36,7 @@ class AlteraModule : public ClangTidyModule {
3536
}
3637
};
3738

39+
} // namespace
3840
} // namespace altera
3941

4042
// Register the AlteraTidyModule using this statically initialized variable.

clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ using namespace clang::ast_matchers;
2929

3030
namespace clang::tidy {
3131
namespace android {
32+
namespace {
3233

3334
/// This module is for Android specific checks.
3435
class AndroidModule : public ClangTidyModule {
@@ -59,6 +60,8 @@ class AndroidModule : public ClangTidyModule {
5960
}
6061
};
6162

63+
} // namespace
64+
6265
// Register the AndroidTidyModule using this statically initialized variable.
6366
static ClangTidyModuleRegistry::Add<AndroidModule>
6467
X("android-module", "Adds Android platform checks.");

clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using namespace clang::ast_matchers;
1515

1616
namespace clang::tidy {
1717
namespace boost {
18+
namespace {
1819

1920
class BoostModule : public ClangTidyModule {
2021
public:
@@ -24,6 +25,8 @@ class BoostModule : public ClangTidyModule {
2425
}
2526
};
2627

28+
} // namespace
29+
2730
// Register the BoostModule using this statically initialized variable.
2831
static ClangTidyModuleRegistry::Add<BoostModule> X("boost-module",
2932
"Add boost checks.");

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115

116116
namespace clang::tidy {
117117
namespace bugprone {
118+
namespace {
118119

119120
class BugproneModule : public ClangTidyModule {
120121
public:
@@ -319,6 +320,7 @@ class BugproneModule : public ClangTidyModule {
319320
}
320321
};
321322

323+
} // namespace
322324
} // namespace bugprone
323325

324326
// Register the BugproneTidyModule using this statically initialized variable.

clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ static bool prefixSuffixCoverUnderThreshold(std::size_t Threshold,
106106

107107
namespace model {
108108

109+
namespace {
110+
109111
/// The language features involved in allowing the mix between two parameters.
110112
enum class MixFlags : unsigned char {
111113
Invalid = 0, ///< Sentinel bit pattern. DO NOT USE!
@@ -129,6 +131,9 @@ enum class MixFlags : unsigned char {
129131

130132
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue =*/ImplicitConversion)
131133
};
134+
135+
} // namespace
136+
132137
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
133138

134139
/// Returns whether the SearchedFlag is turned on in the Data.
@@ -179,6 +184,8 @@ static inline std::string formatMixFlags(MixFlags F) {
179184

180185
#endif // NDEBUG
181186

187+
namespace {
188+
182189
/// The results of the steps of an Implicit Conversion Sequence is saved in
183190
/// an instance of this record.
184191
///
@@ -565,6 +572,8 @@ enum class ImplicitConversionModellingMode : unsigned char {
565572
OneWaySingleStandardOnly
566573
};
567574

575+
} // namespace
576+
568577
static MixData
569578
isLRefEquallyBindingToType(const TheCheck &Check,
570579
const LValueReferenceType *LRef, QualType Ty,
@@ -1594,6 +1603,8 @@ static bool lazyMapOfSetsIntersectionExists(const MapTy &Map, const ElemTy &E1,
15941603
});
15951604
}
15961605

1606+
namespace {
1607+
15971608
/// Implements the heuristic that marks two parameters related if there is
15981609
/// a usage for both in the same strict expression subtree. A strict
15991610
/// expression subtree is a tree which only includes Expr nodes, i.e. no
@@ -1755,6 +1766,8 @@ class Returned {
17551766
}
17561767
};
17571768

1769+
} // namespace
1770+
17581771
} // namespace relatedness_heuristic
17591772

17601773
/// 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) {
19501963
/// Returns whether a particular Mix between the two parameters should have
19511964
/// implicit conversions elaborated.
19521965
static inline bool needsToElaborateImplicitConversion(const model::Mix &M) {
1953-
return hasFlag(M.flags(), model::MixFlags::ImplicitConversion);
1966+
return model::hasFlag(M.flags(), model::MixFlags::ImplicitConversion);
19541967
}
19551968

19561969
namespace {

clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ constexpr StringRef LengthExprName = "LengthExpr";
3232
constexpr StringRef WrongLengthExprName = "WrongLength";
3333
constexpr StringRef UnknownLengthName = "UnknownLength";
3434

35+
namespace {
3536
enum class LengthHandleKind { Increase, Decrease };
37+
} // namespace
3638

37-
namespace {
3839
static Preprocessor *PP;
39-
} // namespace
4040

4141
// Returns the expression of destination's capacity which is part of a
4242
// 'VariableArrayType', 'ConstantArrayTypeLoc' or an argument of a 'malloc()'

clang-tools-extra/clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) {
4040
this);
4141
}
4242

43+
namespace {
44+
4345
class CharExpressionDetector {
4446
public:
4547
CharExpressionDetector(QualType CharType, const ASTContext &Ctx)
@@ -124,6 +126,8 @@ class CharExpressionDetector {
124126
const ASTContext &Ctx;
125127
};
126128

129+
} // namespace
130+
127131
void StringIntegerAssignmentCheck::check(
128132
const MatchFinder::MatchResult &Result) {
129133
const auto *Argument = Result.Nodes.getNodeAs<Expr>("expr");

0 commit comments

Comments
 (0)