Skip to content

Commit d0ed8bc

Browse files
authored
[clang-tidy][NFC] Fix llvm-prefer-static-over-anonymous-namespace warnings 4/N (#164158)
Continue #153885.
1 parent fbb15f5 commit d0ed8bc

16 files changed

+60
-89
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ namespace {
2020

2121
AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
2222

23-
std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal,
24-
const ASTContext &Context) {
23+
} // anonymous namespace
24+
25+
static std::optional<std::string>
26+
makeCharacterLiteral(const StringLiteral *Literal, const ASTContext &Context) {
2527
assert(Literal->getLength() == 1 &&
2628
"Only single character string should be matched");
2729
assert(Literal->getCharByteWidth() == 1 &&
@@ -53,8 +55,6 @@ std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal,
5355
return Result;
5456
}
5557

56-
} // anonymous namespace
57-
5858
void FasterStrsplitDelimiterCheck::registerMatchers(MatchFinder *Finder) {
5959
// Binds to one character string literals.
6060
const auto SingleChar =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct ChainedComparisonData {
5151
void extract(const CXXOperatorCallExpr *Op);
5252
};
5353

54+
} // namespace
55+
5456
void ChainedComparisonData::add(const Expr *Operand) {
5557
if (!Name.empty())
5658
Name += ' ';
@@ -111,8 +113,6 @@ void ChainedComparisonData::extract(const Expr *Op) {
111113
}
112114
}
113115

114-
} // namespace
115-
116116
void ChainedComparisonCheck::registerMatchers(MatchFinder *Finder) {
117117
const auto OperatorMatcher = expr(anyOf(
118118
binaryOperator(isComparisonOperator(),

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ using namespace clang::tidy::matchers;
1717

1818
namespace clang::tidy::bugprone {
1919

20-
namespace {
21-
22-
ast_matchers::internal::BindableMatcher<Stmt>
20+
static ast_matchers::internal::BindableMatcher<Stmt>
2321
handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
2422
const ast_matchers::internal::Matcher<Expr> &Arg) {
2523
return expr(
@@ -31,7 +29,7 @@ handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
3129
on(Arg))));
3230
}
3331

34-
ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue(
32+
static ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue(
3533
const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle) {
3634

3735
const auto TemporaryExpr = anyOf(
@@ -49,22 +47,22 @@ ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue(
4947
return handleFrom(IsAHandle, anyOf(TemporaryExpr, TemporaryTernary));
5048
}
5149

52-
ast_matchers::internal::Matcher<RecordDecl> isASequence() {
50+
static ast_matchers::internal::Matcher<RecordDecl> isASequence() {
5351
return hasAnyName("::std::deque", "::std::forward_list", "::std::list",
5452
"::std::vector");
5553
}
5654

57-
ast_matchers::internal::Matcher<RecordDecl> isASet() {
55+
static ast_matchers::internal::Matcher<RecordDecl> isASet() {
5856
return hasAnyName("::std::set", "::std::multiset", "::std::unordered_set",
5957
"::std::unordered_multiset");
6058
}
6159

62-
ast_matchers::internal::Matcher<RecordDecl> isAMap() {
60+
static ast_matchers::internal::Matcher<RecordDecl> isAMap() {
6361
return hasAnyName("::std::map", "::std::multimap", "::std::unordered_map",
6462
"::std::unordered_multimap");
6563
}
6664

67-
ast_matchers::internal::BindableMatcher<Stmt> makeContainerMatcher(
65+
static ast_matchers::internal::BindableMatcher<Stmt> makeContainerMatcher(
6866
const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle) {
6967
// This matcher could be expanded to detect:
7068
// - Constructors: eg. vector<string_view>(3, string("A"));
@@ -91,8 +89,6 @@ ast_matchers::internal::BindableMatcher<Stmt> makeContainerMatcher(
9189
hasOverloadedOperatorName("[]"))));
9290
}
9391

94-
} // anonymous namespace
95-
9692
DanglingHandleCheck::DanglingHandleCheck(StringRef Name,
9793
ClangTidyContext *Context)
9894
: ClangTidyCheck(Name, Context),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,
5050

5151
AST_MATCHER(Expr, offsetOfExpr) { return isa<OffsetOfExpr>(Node); }
5252

53-
CharUnits getSizeOfType(const ASTContext &Ctx, const Type *Ty) {
53+
} // namespace
54+
55+
static CharUnits getSizeOfType(const ASTContext &Ctx, const Type *Ty) {
5456
if (!Ty || Ty->isIncompleteType() || Ty->isDependentType() ||
5557
isa<DependentSizedArrayType>(Ty) || !Ty->isConstantSizeType())
5658
return CharUnits::Zero();
5759
return Ctx.getTypeSizeInChars(Ty);
5860
}
5961

60-
} // namespace
61-
6262
SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
6363
ClangTidyContext *Context)
6464
: ClangTidyCheck(Name, Context),

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ namespace {
2020
AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
2121
return Node.getValue().getZExtValue() > N;
2222
}
23+
} // namespace
2324

24-
const char DefaultStringNames[] =
25+
static const char DefaultStringNames[] =
2526
"::std::basic_string;::std::basic_string_view";
2627

2728
static std::vector<StringRef>
@@ -36,8 +37,6 @@ removeNamespaces(const std::vector<StringRef> &Names) {
3637
return Result;
3738
}
3839

39-
} // namespace
40-
4140
StringConstructorCheck::StringConstructorCheck(StringRef Name,
4241
ClangTidyContext *Context)
4342
: ClangTidyCheck(Name, Context),

clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ namespace {
2121

2222
AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); }
2323

24-
FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
24+
} // namespace
25+
26+
static FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
2527
if (IsConst && (Decl->getStorageClass() != SC_Static)) {
2628
// No fix available if it is not a static constant, since it is difficult
2729
// to determine the proper fix in this case.
@@ -52,7 +54,6 @@ FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
5254
CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
5355
llvm::StringRef(NewName));
5456
}
55-
} // namespace
5657

5758
void GlobalVariableDeclarationCheck::registerMatchers(MatchFinder *Finder) {
5859
// need to add two matchers since we need to bind different ids to distinguish

clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ using namespace clang::ast_matchers;
1616

1717
namespace clang::tidy::llvm_libc {
1818

19-
namespace {
20-
21-
const TemplateParameterList *
19+
static const TemplateParameterList *
2220
getLastTemplateParameterList(const FunctionDecl *FuncDecl) {
2321
const TemplateParameterList *ReturnList =
2422
FuncDecl->getDescribedTemplateParams();
@@ -35,8 +33,6 @@ getLastTemplateParameterList(const FunctionDecl *FuncDecl) {
3533
return ReturnList;
3634
}
3735

38-
} // namespace
39-
4036
InlineFunctionDeclCheck::InlineFunctionDeclCheck(StringRef Name,
4137
ClangTidyContext *Context)
4238
: ClangTidyCheck(Name, Context),

clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ using namespace clang::ast_matchers;
2222

2323
namespace clang::tidy::misc {
2424

25-
namespace {
26-
bool isOverrideMethod(const FunctionDecl *Function) {
25+
static bool isOverrideMethod(const FunctionDecl *Function) {
2726
if (const auto *MD = dyn_cast<CXXMethodDecl>(Function))
2827
return MD->size_overridden_methods() > 0 || MD->hasAttr<OverrideAttr>();
2928
return false;
3029
}
3130

32-
bool hasAttrAfterParam(const SourceManager *SourceManager,
33-
const ParmVarDecl *Param) {
31+
static bool hasAttrAfterParam(const SourceManager *SourceManager,
32+
const ParmVarDecl *Param) {
3433
for (const auto *Attr : Param->attrs()) {
3534
if (SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
3635
Attr->getLocation())) {
@@ -39,7 +38,6 @@ bool hasAttrAfterParam(const SourceManager *SourceManager,
3938
}
4039
return false;
4140
}
42-
} // namespace
4341

4442
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
4543
Finder->addMatcher(functionDecl(isDefinition(), hasBody(stmt()),

clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ using namespace clang::ast_matchers;
1414

1515
namespace clang::tidy::modernize {
1616

17-
namespace {
18-
1917
// Determine if the given QualType is a nullary function or pointer to same.
20-
bool protoTypeHasNoParms(QualType QT) {
18+
static bool protoTypeHasNoParms(QualType QT) {
2119
if (const auto *PT = QT->getAs<PointerType>())
2220
QT = PT->getPointeeType();
2321
if (auto *MPT = QT->getAs<MemberPointerType>())
@@ -27,16 +25,14 @@ bool protoTypeHasNoParms(QualType QT) {
2725
return false;
2826
}
2927

30-
const char FunctionId[] = "function";
31-
const char TypedefId[] = "typedef";
32-
const char FieldId[] = "field";
33-
const char VarId[] = "var";
34-
const char NamedCastId[] = "named-cast";
35-
const char CStyleCastId[] = "c-style-cast";
36-
const char ExplicitCastId[] = "explicit-cast";
37-
const char LambdaId[] = "lambda";
38-
39-
} // namespace
28+
static const char FunctionId[] = "function";
29+
static const char TypedefId[] = "typedef";
30+
static const char FieldId[] = "field";
31+
static const char VarId[] = "var";
32+
static const char NamedCastId[] = "named-cast";
33+
static const char CStyleCastId[] = "c-style-cast";
34+
static const char ExplicitCastId[] = "explicit-cast";
35+
static const char LambdaId[] = "lambda";
4036

4137
void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
4238
Finder->addMatcher(functionDecl(parameterCountIs(0), unless(isImplicit()),

clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ struct MatchBuilder {
255255
double DiffThreshold;
256256
};
257257

258-
std::string getCode(const StringRef Constant, const bool IsFloat,
259-
const bool IsLongDouble) {
258+
} // namespace
259+
260+
static std::string getCode(const StringRef Constant, const bool IsFloat,
261+
const bool IsLongDouble) {
260262
if (IsFloat) {
261263
return ("std::numbers::" + Constant + "_v<float>").str();
262264
}
@@ -266,9 +268,9 @@ std::string getCode(const StringRef Constant, const bool IsFloat,
266268
return ("std::numbers::" + Constant).str();
267269
}
268270

269-
bool isRangeOfCompleteMacro(const clang::SourceRange &Range,
270-
const clang::SourceManager &SM,
271-
const clang::LangOptions &LO) {
271+
static bool isRangeOfCompleteMacro(const clang::SourceRange &Range,
272+
const clang::SourceManager &SM,
273+
const clang::LangOptions &LO) {
272274
if (!Range.getBegin().isMacroID()) {
273275
return false;
274276
}
@@ -287,8 +289,6 @@ bool isRangeOfCompleteMacro(const clang::SourceRange &Range,
287289
return true;
288290
}
289291

290-
} // namespace
291-
292292
namespace clang::tidy::modernize {
293293
UseStdNumbersCheck::UseStdNumbersCheck(const StringRef Name,
294294
ClangTidyContext *const Context)

0 commit comments

Comments
 (0)