Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ namespace {

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

std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal,
const ASTContext &Context) {
} // anonymous namespace

static std::optional<std::string>
makeCharacterLiteral(const StringLiteral *Literal, const ASTContext &Context) {
assert(Literal->getLength() == 1 &&
"Only single character string should be matched");
assert(Literal->getCharByteWidth() == 1 &&
Expand Down Expand Up @@ -53,8 +55,6 @@ std::optional<std::string> makeCharacterLiteral(const StringLiteral *Literal,
return Result;
}

} // anonymous namespace

void FasterStrsplitDelimiterCheck::registerMatchers(MatchFinder *Finder) {
// Binds to one character string literals.
const auto SingleChar =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct ChainedComparisonData {
void extract(const CXXOperatorCallExpr *Op);
};

} // namespace

void ChainedComparisonData::add(const Expr *Operand) {
if (!Name.empty())
Name += ' ';
Expand Down Expand Up @@ -111,8 +113,6 @@ void ChainedComparisonData::extract(const Expr *Op) {
}
}

} // namespace

void ChainedComparisonCheck::registerMatchers(MatchFinder *Finder) {
const auto OperatorMatcher = expr(anyOf(
binaryOperator(isComparisonOperator(),
Expand Down
16 changes: 6 additions & 10 deletions clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ using namespace clang::tidy::matchers;

namespace clang::tidy::bugprone {

namespace {

ast_matchers::internal::BindableMatcher<Stmt>
static ast_matchers::internal::BindableMatcher<Stmt>
handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
const ast_matchers::internal::Matcher<Expr> &Arg) {
return expr(
Expand All @@ -31,7 +29,7 @@ handleFrom(const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle,
on(Arg))));
}

ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue(
static ast_matchers::internal::Matcher<Stmt> handleFromTemporaryValue(
const ast_matchers::internal::Matcher<RecordDecl> &IsAHandle) {

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

ast_matchers::internal::Matcher<RecordDecl> isASequence() {
static ast_matchers::internal::Matcher<RecordDecl> isASequence() {
return hasAnyName("::std::deque", "::std::forward_list", "::std::list",
"::std::vector");
}

ast_matchers::internal::Matcher<RecordDecl> isASet() {
static ast_matchers::internal::Matcher<RecordDecl> isASet() {
return hasAnyName("::std::set", "::std::multiset", "::std::unordered_set",
"::std::unordered_multiset");
}

ast_matchers::internal::Matcher<RecordDecl> isAMap() {
static ast_matchers::internal::Matcher<RecordDecl> isAMap() {
return hasAnyName("::std::map", "::std::multimap", "::std::unordered_map",
"::std::unordered_multimap");
}

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

} // anonymous namespace

DanglingHandleCheck::DanglingHandleCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,

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

CharUnits getSizeOfType(const ASTContext &Ctx, const Type *Ty) {
} // namespace

static CharUnits getSizeOfType(const ASTContext &Ctx, const Type *Ty) {
if (!Ty || Ty->isIncompleteType() || Ty->isDependentType() ||
isa<DependentSizedArrayType>(Ty) || !Ty->isConstantSizeType())
return CharUnits::Zero();
return Ctx.getTypeSizeInChars(Ty);
}

} // namespace

SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ namespace {
AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
return Node.getValue().getZExtValue() > N;
}
} // namespace

const char DefaultStringNames[] =
static const char DefaultStringNames[] =
"::std::basic_string;::std::basic_string_view";

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

} // namespace

StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ namespace {

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

FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
} // namespace

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

void GlobalVariableDeclarationCheck::registerMatchers(MatchFinder *Finder) {
// need to add two matchers since we need to bind different ids to distinguish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ using namespace clang::ast_matchers;

namespace clang::tidy::llvm_libc {

namespace {

const TemplateParameterList *
static const TemplateParameterList *
getLastTemplateParameterList(const FunctionDecl *FuncDecl) {
const TemplateParameterList *ReturnList =
FuncDecl->getDescribedTemplateParams();
Expand All @@ -35,8 +33,6 @@ getLastTemplateParameterList(const FunctionDecl *FuncDecl) {
return ReturnList;
}

} // namespace

InlineFunctionDeclCheck::InlineFunctionDeclCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Expand Down
8 changes: 3 additions & 5 deletions clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ using namespace clang::ast_matchers;

namespace clang::tidy::misc {

namespace {
bool isOverrideMethod(const FunctionDecl *Function) {
static bool isOverrideMethod(const FunctionDecl *Function) {
if (const auto *MD = dyn_cast<CXXMethodDecl>(Function))
return MD->size_overridden_methods() > 0 || MD->hasAttr<OverrideAttr>();
return false;
}

bool hasAttrAfterParam(const SourceManager *SourceManager,
const ParmVarDecl *Param) {
static bool hasAttrAfterParam(const SourceManager *SourceManager,
const ParmVarDecl *Param) {
for (const auto *Attr : Param->attrs()) {
if (SourceManager->isBeforeInTranslationUnit(Param->getLocation(),
Attr->getLocation())) {
Expand All @@ -39,7 +38,6 @@ bool hasAttrAfterParam(const SourceManager *SourceManager,
}
return false;
}
} // namespace

void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(functionDecl(isDefinition(), hasBody(stmt()),
Expand Down
22 changes: 9 additions & 13 deletions clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ using namespace clang::ast_matchers;

namespace clang::tidy::modernize {

namespace {

// Determine if the given QualType is a nullary function or pointer to same.
bool protoTypeHasNoParms(QualType QT) {
static bool protoTypeHasNoParms(QualType QT) {
if (const auto *PT = QT->getAs<PointerType>())
QT = PT->getPointeeType();
if (auto *MPT = QT->getAs<MemberPointerType>())
Expand All @@ -27,16 +25,14 @@ bool protoTypeHasNoParms(QualType QT) {
return false;
}

const char FunctionId[] = "function";
const char TypedefId[] = "typedef";
const char FieldId[] = "field";
const char VarId[] = "var";
const char NamedCastId[] = "named-cast";
const char CStyleCastId[] = "c-style-cast";
const char ExplicitCastId[] = "explicit-cast";
const char LambdaId[] = "lambda";

} // namespace
static const char FunctionId[] = "function";
static const char TypedefId[] = "typedef";
static const char FieldId[] = "field";
static const char VarId[] = "var";
static const char NamedCastId[] = "named-cast";
static const char CStyleCastId[] = "c-style-cast";
static const char ExplicitCastId[] = "explicit-cast";
static const char LambdaId[] = "lambda";

void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(functionDecl(parameterCountIs(0), unless(isImplicit()),
Expand Down
14 changes: 7 additions & 7 deletions clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ struct MatchBuilder {
double DiffThreshold;
};

std::string getCode(const StringRef Constant, const bool IsFloat,
const bool IsLongDouble) {
} // namespace

static std::string getCode(const StringRef Constant, const bool IsFloat,
const bool IsLongDouble) {
if (IsFloat) {
return ("std::numbers::" + Constant + "_v<float>").str();
}
Expand All @@ -266,9 +268,9 @@ std::string getCode(const StringRef Constant, const bool IsFloat,
return ("std::numbers::" + Constant).str();
}

bool isRangeOfCompleteMacro(const clang::SourceRange &Range,
const clang::SourceManager &SM,
const clang::LangOptions &LO) {
static bool isRangeOfCompleteMacro(const clang::SourceRange &Range,
const clang::SourceManager &SM,
const clang::LangOptions &LO) {
if (!Range.getBegin().isMacroID()) {
return false;
}
Expand All @@ -287,8 +289,6 @@ bool isRangeOfCompleteMacro(const clang::SourceRange &Range,
return true;
}

} // namespace

namespace clang::tidy::modernize {
UseStdNumbersCheck::UseStdNumbersCheck(const StringRef Name,
ClangTidyContext *const Context)
Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const std::uint64_t Min32 =
std::imaxabs(std::numeric_limits<std::int32_t>::min());
const std::uint64_t Max32 = std::numeric_limits<std::int32_t>::max();

std::pair<const char *, std::uint32_t>
} // namespace
static std::pair<const char *, std::uint32_t>
getNewType(std::size_t Size, std::uint64_t Min, std::uint64_t Max) noexcept {
if (Min) {
if (Min <= Min8 && Max <= Max8) {
Expand Down Expand Up @@ -75,8 +76,6 @@ getNewType(std::size_t Size, std::uint64_t Min, std::uint64_t Max) noexcept {
return {"std::uint8_t", sizeof(std::uint8_t)};
}

} // namespace

EnumSizeCheck::EnumSizeCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
EnumIgnoreList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
using namespace clang::ast_matchers;

namespace clang::tidy::readability {
namespace {

SourceRange getTypeRange(const ParmVarDecl &Param) {
static SourceRange getTypeRange(const ParmVarDecl &Param) {
return {Param.getBeginLoc(), Param.getLocation().getLocWithOffset(-1)};
}

Expand All @@ -39,8 +38,6 @@ findConstToRemove(const ParmVarDecl &Param,
tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
}

} // namespace

void AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ void RedundantSmartptrGetCheck::registerMatchers(MatchFinder *Finder) {
registerMatchersForGetEquals(Finder, this);
}

namespace {
bool allReturnTypesMatch(const MatchFinder::MatchResult &Result) {
static bool allReturnTypesMatch(const MatchFinder::MatchResult &Result) {
if (Result.Nodes.getNodeAs<Decl>("duck_typing") == nullptr)
return true;
// Verify that the types match.
Expand All @@ -145,7 +144,6 @@ bool allReturnTypesMatch(const MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<Type>("getType")->getUnqualifiedDesugaredType();
return OpArrowType == OpStarType && OpArrowType == GetType;
}
} // namespace

void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) {
if (!allReturnTypesMatch(Result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ using namespace clang::ast_matchers;

namespace clang::tidy::readability {

namespace {

StringRef getText(const ASTContext &Context, SourceRange Range) {
static StringRef getText(const ASTContext &Context, SourceRange Range) {
return Lexer::getSourceText(CharSourceRange::getTokenRange(Range),
Context.getSourceManager(),
Context.getLangOpts());
}

template <typename T> StringRef getText(const ASTContext &Context, T &Node) {
template <typename T>
static StringRef getText(const ASTContext &Context, T &Node) {
return getText(Context, Node.getSourceRange());
}

} // namespace

static constexpr char SimplifyOperatorDiagnostic[] =
"redundant boolean literal supplied to boolean operator";
static constexpr char SimplifyConditionDiagnostic[] =
Expand Down
14 changes: 5 additions & 9 deletions clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ static SmallVector<const Stmt *, 1> getParentStmts(const Stmt *S,
return Result;
}

namespace {

bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor,
ASTContext *Context) {
static bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor,
ASTContext *Context) {
if (Descendant == Ancestor)
return true;
return llvm::any_of(getParentStmts(Descendant, Context),
Expand All @@ -61,15 +59,15 @@ bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor,
});
}

bool isDescendantOfArgs(const Stmt *Descendant, const CallExpr *Call,
ASTContext *Context) {
static bool isDescendantOfArgs(const Stmt *Descendant, const CallExpr *Call,
ASTContext *Context) {
return llvm::any_of(Call->arguments(),
[Descendant, Context](const Expr *Arg) {
return isDescendantOrEqual(Descendant, Arg, Context);
});
}

llvm::SmallVector<const InitListExpr *>
static llvm::SmallVector<const InitListExpr *>
getAllInitListForms(const InitListExpr *InitList) {
llvm::SmallVector<const InitListExpr *> Result = {InitList};
if (const InitListExpr *AltForm = InitList->getSyntacticForm())
Expand All @@ -79,8 +77,6 @@ getAllInitListForms(const InitListExpr *InitList) {
return Result;
}

} // namespace

ExprSequence::ExprSequence(const CFG *TheCFG, const Stmt *Root,
ASTContext *TheContext)
: Context(TheContext), Root(Root) {
Expand Down
Loading