[clang-tools-extra] [clang-tidy] detect explicit casting within modernize-use-default-member-init (PR #129408)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 11 10:30:19 PDT 2025
================
@@ -194,15 +199,21 @@ void UseDefaultMemberInitCheck::storeOptions(
}
void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
- auto InitBase =
- anyOf(stringLiteral(), characterLiteral(), integerLiteral(),
- unaryOperator(hasAnyOperatorName("+", "-"),
- hasUnaryOperand(integerLiteral())),
- floatLiteral(),
- unaryOperator(hasAnyOperatorName("+", "-"),
- hasUnaryOperand(floatLiteral())),
- cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
- declRefExpr(to(enumConstantDecl())));
+
+ auto ExplicitCastExpr = castExpr(hasSourceExpression(anyOf(
+ unaryOperator(hasAnyOperatorName("+", "-"),
+ hasUnaryOperand(anyOf(integerLiteral(), floatLiteral()))),
+ integerLiteral(), floatLiteral(), characterLiteral())));
----------------
PiotrZSL wrote:
on other hand, instead typing here all those literals and unary operators, you could simply use thing like this:
```
anyOf(InitBase, castExpr(hasSourceExpression(InitBase)))
```
should do a trick...
https://github.com/llvm/llvm-project/pull/129408
More information about the cfe-commits
mailing list