Skip to content

[clang-tidy][NFC] change patterns 'anyOf(..., anything())' to 'optionally(...)' #143558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2025
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 @@ -702,17 +702,16 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) {
return hasArgument(
CC.LengthPos,
allOf(
anyOf(
ignoringImpCasts(integerLiteral().bind(WrongLengthExprName)),
allOf(unless(hasDefinition(SizeOfCharExpr)),
allOf(CC.WithIncrease
? ignoringImpCasts(hasDefinition(HasIncOp))
: ignoringImpCasts(allOf(
unless(hasDefinition(HasIncOp)),
anyOf(hasDefinition(binaryOperator().bind(
UnknownLengthName)),
hasDefinition(anything())))),
AnyOfWrongLengthInit))),
anyOf(ignoringImpCasts(integerLiteral().bind(WrongLengthExprName)),
allOf(unless(hasDefinition(SizeOfCharExpr)),
allOf(CC.WithIncrease
? ignoringImpCasts(hasDefinition(HasIncOp))
: ignoringImpCasts(
allOf(unless(hasDefinition(HasIncOp)),
hasDefinition(optionally(
binaryOperator().bind(
UnknownLengthName))))),
AnyOfWrongLengthInit))),
expr().bind(LengthExprName)));
};

Expand Down
12 changes: 5 additions & 7 deletions clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ void ExceptionBaseclassCheck::registerMatchers(MatchFinder *Finder) {
isSameOrDerivedFrom(hasName("::std::exception")))))))))),
// This condition is always true, but will bind to the
// template value if the thrown type is templated.
anyOf(has(expr(
hasType(substTemplateTypeParmType().bind("templ_type")))),
anything()),
optionally(has(
expr(hasType(substTemplateTypeParmType().bind("templ_type"))))),
// Bind to the declaration of the type of the value that
// is thrown. 'anything()' is necessary to always succeed
// in the 'eachOf' because builtin types are not
// 'namedDecl'.
eachOf(has(expr(hasType(namedDecl().bind("decl")))), anything()))
// is thrown. 'optionally' is necessary because builtin types
// are not 'namedDecl'.
optionally(has(expr(hasType(namedDecl().bind("decl"))))))
.bind("bad_throw"),
this);
}
Expand Down
13 changes: 5 additions & 8 deletions clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
binaryOperator(
hasAnyOperatorName("&&", "=="),
hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))),
anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
anything()))
optionally(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast))))
.bind("assertExprRoot"),
IsAlwaysFalse);
auto NonConstexprFunctionCall =
Expand All @@ -52,12 +51,10 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
auto NonConstexprCode =
expr(anyOf(NonConstexprFunctionCall, NonConstexprVariableReference));
auto AssertCondition =
expr(
anyOf(expr(ignoringParenCasts(anyOf(
AssertExprRoot, unaryOperator(hasUnaryOperand(
ignoringParenCasts(AssertExprRoot)))))),
anything()),
unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
expr(optionally(expr(ignoringParenCasts(anyOf(
AssertExprRoot, unaryOperator(hasUnaryOperand(
ignoringParenCasts(AssertExprRoot))))))),
unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
.bind("condition");
auto Condition =
anyOf(ignoringParenImpCasts(callExpr(
Expand Down
13 changes: 6 additions & 7 deletions clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ void UseBoolLiteralsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {

void UseBoolLiteralsCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
traverse(
TK_AsIs,
implicitCastExpr(
has(ignoringParenImpCasts(integerLiteral().bind("literal"))),
hasImplicitDestinationType(qualType(booleanType())),
unless(isInTemplateInstantiation()),
anyOf(hasParent(explicitCastExpr().bind("cast")), anything()))),
traverse(TK_AsIs,
implicitCastExpr(
has(ignoringParenImpCasts(integerLiteral().bind("literal"))),
hasImplicitDestinationType(qualType(booleanType())),
unless(isInTemplateInstantiation()),
optionally(hasParent(explicitCastExpr().bind("cast"))))),
this);

Finder->addMatcher(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
implicitCastExpr().bind("implicitCastFromBool"),
unless(hasParent(BitfieldConstruct)),
// Check also for nested casts, for example: bool -> int -> float.
anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
anything()),
optionally(
hasParent(implicitCastExpr().bind("furtherImplicitCast"))),
unless(isInTemplateInstantiation()),
unless(IsInCompilerGeneratedFunction))),
this);
Expand Down
Loading