[clang-tools-extra] f46c44d - [clang-tidy][NFC] change patterns 'anyOf(..., anything())' to 'optionally(...)' (#143558)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 14 00:55:45 PDT 2025
Author: Baranov Victor
Date: 2025-06-14T10:55:42+03:00
New Revision: f46c44dbc0d225277178cf5b6646a96f591fdeaa
URL: https://github.com/llvm/llvm-project/commit/f46c44dbc0d225277178cf5b6646a96f591fdeaa
DIFF: https://github.com/llvm/llvm-project/commit/f46c44dbc0d225277178cf5b6646a96f591fdeaa.diff
LOG: [clang-tidy][NFC] change patterns 'anyOf(..., anything())' to 'optionally(...)' (#143558)
Writing `optionally()` instead of `anyOf(..., anything())` lowers code
size and gives the author's intention better.
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index bedecb60569e8..203170d55f694 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -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)));
};
diff --git a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
index 2b2acfdf5b08e..ed39568ea554a 100644
--- a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
@@ -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);
}
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index faff1c17fc61e..37fbd8c0d725f 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -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 =
@@ -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(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
index c8e6bf47bb82f..339462093a6d6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
@@ -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(
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index f9fd1d903e231..20c73299915a9 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -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);
More information about the cfe-commits
mailing list