[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.
This commit is contained in:
@@ -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)));
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user