Skip to content

Commit 84b0e0c

Browse files
vbvictorgithub-actions[bot]
authored andcommitted
Automerge: [clang-tidy][NFC] Fix llvm-prefer-static-over-anonymous-namespace warnings 3/N (#164085)
Continue llvm/llvm-project#153885.
2 parents ad56841 + f5ae102 commit 84b0e0c

File tree

11 files changed

+70
-68
lines changed

11 files changed

+70
-68
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ using namespace clang::ast_matchers;
1616

1717
namespace clang::tidy::android {
1818

19-
namespace {
2019
// Helper function to form the correct string mode for Type3.
2120
// Build the replace text. If it's string constant, add <Mode> directly in the
2221
// end of the string. Else, add <Mode>.
23-
std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,
24-
const LangOptions &LangOpts, char Mode) {
22+
static std::string buildFixMsgForStringFlag(const Expr *Arg,
23+
const SourceManager &SM,
24+
const LangOptions &LangOpts,
25+
char Mode) {
2526
if (Arg->getBeginLoc().isMacroID())
2627
return (Lexer::getSourceText(
2728
CharSourceRange::getTokenRange(Arg->getSourceRange()), SM,
@@ -32,11 +33,6 @@ std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,
3233
StringRef SR = cast<StringLiteral>(Arg->IgnoreParenCasts())->getString();
3334
return ("\"" + SR + Twine(Mode) + "\"").str();
3435
}
35-
} // namespace
36-
37-
const char *CloexecCheck::FuncDeclBindingStr = "funcDecl";
38-
39-
const char *CloexecCheck::FuncBindingStr = "func";
4036

4137
void CloexecCheck::registerMatchersImpl(
4238
MatchFinder *Finder, internal::Matcher<FunctionDecl> Function) {

clang-tools-extra/clang-tidy/android/CloexecCheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ class CloexecCheck : public ClangTidyCheck {
8989
int N) const;
9090

9191
/// Binding name of the FuncDecl of a function call.
92-
static const char *FuncDeclBindingStr;
92+
static constexpr char FuncDeclBindingStr[] = "funcDecl";
9393

9494
/// Binding name of the function call expression.
95-
static const char *FuncBindingStr;
95+
static constexpr char FuncBindingStr[] = "func";
9696
};
9797

9898
} // namespace clang::tidy::android

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,10 @@ struct OptionEnumMapping<
245245

246246
namespace bugprone {
247247

248-
namespace {
249-
250248
/// Returns if a function is declared inside a system header.
251249
/// These functions are considered to be "standard" (system-provided) library
252250
/// functions.
253-
bool isStandardFunction(const FunctionDecl *FD) {
251+
static bool isStandardFunction(const FunctionDecl *FD) {
254252
// Find a possible redeclaration in system header.
255253
// FIXME: Looking at the canonical declaration is not the most exact way
256254
// to do this.
@@ -284,7 +282,7 @@ bool isStandardFunction(const FunctionDecl *FD) {
284282
/// Check if a statement is "C++-only".
285283
/// This includes all statements that have a class name with "CXX" prefix
286284
/// and every other statement that is declared in file ExprCXX.h.
287-
bool isCXXOnlyStmt(const Stmt *S) {
285+
static bool isCXXOnlyStmt(const Stmt *S) {
288286
StringRef Name = S->getStmtClassName();
289287
if (Name.starts_with("CXX"))
290288
return true;
@@ -304,7 +302,8 @@ bool isCXXOnlyStmt(const Stmt *S) {
304302
/// called from \p Caller, get a \c CallExpr of the corresponding function call.
305303
/// It is unspecified which call is found if multiple calls exist, but the order
306304
/// should be deterministic (depend only on the AST).
307-
Expr *findCallExpr(const CallGraphNode *Caller, const CallGraphNode *Callee) {
305+
static Expr *findCallExpr(const CallGraphNode *Caller,
306+
const CallGraphNode *Callee) {
308307
const auto *FoundCallee = llvm::find_if(
309308
Caller->callees(), [Callee](const CallGraphNode::CallRecord &Call) {
310309
return Call.Callee == Callee;
@@ -314,7 +313,7 @@ Expr *findCallExpr(const CallGraphNode *Caller, const CallGraphNode *Callee) {
314313
return FoundCallee->CallExpr;
315314
}
316315

317-
SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
316+
static SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
318317
ParentMapContext &PM = Ctx.getParentMapContext();
319318
DynTypedNode P = DynTypedNode::create(*S);
320319
while (P.getSourceRange().isInvalid()) {
@@ -326,9 +325,9 @@ SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
326325
return P.getSourceRange();
327326
}
328327

329-
AST_MATCHER(FunctionDecl, isStandardFunction) {
330-
return isStandardFunction(&Node);
331-
}
328+
namespace {
329+
330+
AST_MATCHER(FunctionDecl, isStandard) { return isStandardFunction(&Node); }
332331

333332
} // namespace
334333

@@ -354,7 +353,7 @@ bool SignalHandlerCheck::isLanguageVersionSupported(
354353

355354
void SignalHandlerCheck::registerMatchers(MatchFinder *Finder) {
356355
auto SignalFunction = functionDecl(hasAnyName("::signal", "::std::signal"),
357-
parameterCountIs(2), isStandardFunction());
356+
parameterCountIs(2), isStandard());
358357
auto HandlerExpr =
359358
declRefExpr(hasDeclaration(functionDecl().bind("handler_decl")),
360359
unless(isExpandedFromMacro("SIG_IGN")),

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

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

3131
namespace clang::tidy::misc {
32-
namespace {
3332
using llvm::APSInt;
3433

3534
static constexpr llvm::StringLiteral KnownBannedMacroNames[] = {
@@ -420,6 +419,8 @@ markDuplicateOperands(const TExpr *TheExpr,
420419
return Duplicates.any();
421420
}
422421

422+
namespace {
423+
423424
AST_MATCHER(Expr, isIntegerConstantExpr) {
424425
if (Node.isInstantiationDependent())
425426
return false;
@@ -470,6 +471,8 @@ AST_MATCHER_P(Expr, expandedByMacro, ArrayRef<llvm::StringLiteral>, Names) {
470471
return false;
471472
}
472473

474+
} // namespace
475+
473476
// Returns a matcher for integer constant expressions.
474477
static ast_matchers::internal::Matcher<Expr>
475478
matchIntegerConstantExpr(StringRef Id) {
@@ -805,7 +808,8 @@ static bool isSameRawIdentifierToken(const Token &T1, const Token &T2,
805808
StringRef(SM.getCharacterData(T2.getLocation()), T2.getLength());
806809
}
807810

808-
bool isTokAtEndOfExpr(SourceRange ExprSR, Token T, const SourceManager &SM) {
811+
static bool isTokAtEndOfExpr(SourceRange ExprSR, Token T,
812+
const SourceManager &SM) {
809813
return SM.getExpansionLoc(ExprSR.getEnd()) == T.getLocation();
810814
}
811815

@@ -921,7 +925,6 @@ static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp,
921925

922926
return false;
923927
}
924-
} // namespace
925928

926929
void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
927930
const auto BannedIntegerLiteral =

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ void UniqueptrResetReleaseCheck::registerMatchers(MatchFinder *Finder) {
5353
this);
5454
}
5555

56-
namespace {
57-
const Type *getDeleterForUniquePtr(const MatchFinder::MatchResult &Result,
58-
StringRef ID) {
56+
static const Type *
57+
getDeleterForUniquePtr(const MatchFinder::MatchResult &Result, StringRef ID) {
5958
const auto *Class =
6059
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>(ID);
6160
if (!Class)
@@ -66,7 +65,7 @@ const Type *getDeleterForUniquePtr(const MatchFinder::MatchResult &Result,
6665
return DeleterArgument.getAsType().getTypePtr();
6766
}
6867

69-
bool areDeletersCompatible(const MatchFinder::MatchResult &Result) {
68+
static bool areDeletersCompatible(const MatchFinder::MatchResult &Result) {
7069
const Type *LeftDeleterType = getDeleterForUniquePtr(Result, "left_class");
7170
const Type *RightDeleterType = getDeleterForUniquePtr(Result, "right_class");
7271

@@ -103,8 +102,6 @@ bool areDeletersCompatible(const MatchFinder::MatchResult &Result) {
103102
return false;
104103
}
105104

106-
} // namespace
107-
108105
void UniqueptrResetReleaseCheck::check(const MatchFinder::MatchResult &Result) {
109106
if (!areDeletersCompatible(Result))
110107
return;

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ using namespace llvm;
2121
namespace clang::tidy::modernize {
2222
namespace {
2323

24-
const char CastSequence[] = "sequence";
25-
2624
AST_MATCHER(Type, sugaredNullptrType) {
2725
const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
2826
if (const auto *BT = dyn_cast<BuiltinType>(DesugaredType))
2927
return BT->getKind() == BuiltinType::NullPtr;
3028
return false;
3129
}
3230

31+
} // namespace
32+
33+
static const char CastSequence[] = "sequence";
34+
3335
/// Create a matcher that finds implicit casts as well as the head of a
3436
/// sequence of zero or more nested explicit casts that have an implicit cast
3537
/// to null within.
@@ -43,7 +45,8 @@ AST_MATCHER(Type, sugaredNullptrType) {
4345
/// would check for the "NULL" macro instead, but that'd be harder to express.
4446
/// In practice, "NULL" is often defined as "__null", and this is a useful
4547
/// condition.
46-
StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef<StringRef> NameList) {
48+
static StatementMatcher
49+
makeCastSequenceMatcher(llvm::ArrayRef<StringRef> NameList) {
4750
auto ImplicitCastToNull = implicitCastExpr(
4851
anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)),
4952
anyOf(hasSourceExpression(gnuNullExpr()),
@@ -79,16 +82,16 @@ StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef<StringRef> NameList) {
7982
unless(hasAncestor(functionDecl(isDefaulted()))))));
8083
}
8184

82-
bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
83-
const SourceManager &SM) {
85+
static bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
86+
const SourceManager &SM) {
8487
return SM.isWrittenInSameFile(StartLoc, EndLoc);
8588
}
8689

8790
/// Replaces the provided range with the text "nullptr", but only if
8891
/// the start and end location are both in main file.
8992
/// Returns true if and only if a replacement was made.
90-
void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
91-
SourceLocation StartLoc, SourceLocation EndLoc) {
93+
static void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
94+
SourceLocation StartLoc, SourceLocation EndLoc) {
9295
CharSourceRange Range(SourceRange(StartLoc, EndLoc), true);
9396
// Add a space if nullptr follows an alphanumeric character. This happens
9497
// whenever there is an c-style explicit cast to nullptr not surrounded by
@@ -106,8 +109,9 @@ void replaceWithNullptr(ClangTidyCheck &Check, SourceManager &SM,
106109
/// #define MY_NULL NULL
107110
/// \endcode
108111
/// If \p Loc points to NULL, this function will return the name MY_NULL.
109-
StringRef getOutermostMacroName(SourceLocation Loc, const SourceManager &SM,
110-
const LangOptions &LO) {
112+
static StringRef getOutermostMacroName(SourceLocation Loc,
113+
const SourceManager &SM,
114+
const LangOptions &LO) {
111115
assert(Loc.isMacroID());
112116
SourceLocation OutermostMacroLoc;
113117

@@ -119,6 +123,8 @@ StringRef getOutermostMacroName(SourceLocation Loc, const SourceManager &SM,
119123
return Lexer::getImmediateMacroName(OutermostMacroLoc, SM, LO);
120124
}
121125

126+
namespace {
127+
122128
/// RecursiveASTVisitor for ensuring all nodes rooted at a given AST
123129
/// subtree that have file-level source locations corresponding to a macro
124130
/// argument have implicit NullTo(Member)Pointer nodes as ancestors.

clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ using namespace clang::ast_matchers;
1717

1818
namespace clang::tidy::performance {
1919

20-
namespace {
21-
22-
std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal) {
20+
static std::optional<std::string>
21+
makeCharacterLiteral(const StringLiteral *Literal) {
2322
std::string Result;
2423
{
2524
llvm::raw_string_ostream OS(Result);
@@ -43,6 +42,8 @@ std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal) {
4342
return Result;
4443
}
4544

45+
namespace {
46+
4647
AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<Expr>,
4748
hasSubstitutedType) {
4849
return hasType(qualType(anyOf(substTemplateTypeParmType(),

clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ using namespace clang::ast_matchers;
1717

1818
namespace clang::tidy::performance {
1919

20-
namespace {
21-
2220
// Matcher names. Given the code:
2321
//
2422
// \code
@@ -60,12 +58,14 @@ static const char LoopInitVarName[] = "loop_init_var";
6058
static const char LoopEndExprName[] = "loop_end_expr";
6159
static const char RangeLoopName[] = "for_range_loop";
6260

63-
ast_matchers::internal::Matcher<Expr> supportedContainerTypesMatcher() {
61+
static ast_matchers::internal::Matcher<Expr> supportedContainerTypesMatcher() {
6462
return hasType(cxxRecordDecl(hasAnyName(
6563
"::std::vector", "::std::set", "::std::unordered_set", "::std::map",
6664
"::std::unordered_map", "::std::array", "::std::deque")));
6765
}
6866

67+
namespace {
68+
6969
AST_MATCHER(Expr, hasSideEffects) {
7070
return Node.HasSideEffects(Finder->getASTContext());
7171
}

clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class DuplicateIncludeCallbacks : public PPCallbacks {
6464
const SourceManager &SM;
6565
};
6666

67+
} // namespace
68+
6769
void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
6870
FileChangeReason Reason,
6971
SrcMgr::CharacteristicKind FileType,
@@ -107,8 +109,6 @@ void DuplicateIncludeCallbacks::MacroUndefined(const Token &MacroNameTok,
107109
Files.back().clear();
108110
}
109111

110-
} // namespace
111-
112112
void DuplicateIncludeCheck::registerPPCallbacks(
113113
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
114114
PP->addPPCallbacks(std::make_unique<DuplicateIncludeCallbacks>(*this, SM));

0 commit comments

Comments
 (0)