[clang-tools-extra] [clang-tidy] Fix false negative `modernize-use-ranges` when using getter function (PR #127377)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Sun May 25 19:08:25 PDT 2025


================
@@ -51,7 +51,13 @@ static std::string getFullPrefix(ArrayRef<UseRangesCheck::Indexes> Signature) {
 namespace {
 
 AST_MATCHER(Expr, hasSideEffects) {
-  return Node.HasSideEffects(Finder->getASTContext());
+  bool CheckArg = true;
+  if (const CXXMemberCallExpr *Call = dyn_cast<CXXMemberCallExpr>(&Node)) {
+    if (Call->isLValue() && Call->getMethodDecl()->isConst()) {
+      CheckArg = false;
+    }
+  }
----------------
HerrCai0907 wrote:

According to comment in `HasSideEffects`.
>   IncludePossibleEffects is false, this call treats certain expressions with potential side effects (such as function call-like expressions, instantiation-dependent expressions, or invocations from a macro) as not having side effects.

I think there are no relationship between `Call->isLValue() && Call->getMethodDecl()->isConst()` and `IncludePossibleEffects`.

https://github.com/llvm/llvm-project/pull/127377


More information about the cfe-commits mailing list