[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
Fri Nov 15 13:08:45 PST 2024
================
@@ -189,7 +203,54 @@ void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
if (ComparisonExpr->getBeginLoc().isMacroID())
return;
- const bool Neg = ComparisonExpr->getOpcode() == BO_NE;
+ bool Neg;
+ if (const auto *BO = llvm::dyn_cast<BinaryOperator>(ComparisonExpr)) {
+ Neg = BO->getOpcode() == BO_NE;
+ } else {
+ assert(llvm::isa<CXXOperatorCallExpr>(ComparisonExpr));
+ Neg = llvm::cast<CXXOperatorCallExpr>(ComparisonExpr)->getOperator() ==
+ OO_ExclaimEqual;
+ }
----------------
nicovank wrote:
A possible risk of errors here is `RewrittenBinaryOperator` for C++20 and above: sometimes (always?) CXXOperatorCallExpr nodes `operator!=` are rewritten into `not operator==`. I'm not sure if this is something to worry about here, will have to read on it again.
https://github.com/llvm/llvm-project/pull/116033
More information about the cfe-commits
mailing list