[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)
Nicolas van Kempen via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 17 18:16:39 PST 2024
================
@@ -30,6 +30,17 @@ struct NotLengthExprForStringNode {
IntegerLiteralSizeNode->getValue().getZExtValue();
}
+ if (const auto *DeclRefNode = Node.get<DeclRefExpr>()) {
+ if (const auto *VD = dyn_cast<VarDecl>(DeclRefNode->getDecl())) {
+ if (VD->hasInit() && VD->getType().isConstQualified()) {
+ if (const auto *Init = dyn_cast<IntegerLiteral>(VD->getInit())) {
+ return StringLiteralNode->getLength() !=
+ Init->getValue().getZExtValue();
+ }
+ }
+ }
+ }
+
----------------
nicovank wrote:
I'm not sure exactly, what case is this adding? IMO changing `lengthExprForStringNode` can/should happen in subsequent PR; it affects existing `compare`/`find`/`rfind` branches as well.
https://github.com/llvm/llvm-project/pull/116033
More information about the cfe-commits
mailing list