================ @@ -183,40 +210,45 @@ void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) { const auto *EndsWithFunction = Result.Nodes.getNodeAs<CXXMethodDecl>("ends_with_fun"); assert(bool(StartsWithFunction) != bool(EndsWithFunction)); + const CXXMethodDecl *ReplacementFunction = StartsWithFunction ? StartsWithFunction : EndsWithFunction; - if (ComparisonExpr->getBeginLoc().isMacroID()) + if (ComparisonExpr->getBeginLoc().isMacroID() || + FindExpr->getBeginLoc().isMacroID()) return; - const bool Neg = ComparisonExpr->getOpcode() == BO_NE; + const bool Neg = isNegativeComparison(ComparisonExpr); - auto Diagnostic = - diag(FindExpr->getExprLoc(), "use %0 instead of %1() %select{==|!=}2 0") - << ReplacementFunction->getName() << FindFun->getName() << Neg; + // Retrieve the source text of the search expression. + const auto SearchExprText = Lexer::getSourceText( + CharSourceRange::getTokenRange(SearchExpr->getSourceRange()), + *Result.SourceManager, Result.Context->getLangOpts()); - // Remove possible arguments after search expression and ' [!=]= .+' suffix. - Diagnostic << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange( - Lexer::getLocForEndOfToken(SearchExpr->getEndLoc(), 0, - *Result.SourceManager, getLangOpts()), - ComparisonExpr->getEndLoc()), - ")"); + auto Diag = diag(FindExpr->getExprLoc(), + FindFun->getName() == "substr" ---------------- PiotrZSL wrote:
Tip: consider using "select" instead, like "use %0 instead of %1() %select{==|!=}2%select{ 0|)3" and then pass `FindFun->getName() == "substr"` as bool param https://github.com/llvm/llvm-project/pull/116033 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits