[clang-tools-extra] [clang-tidy] Avoid readability-use-anyofallof diagnostics on temporary ranges before C++20 (PR #185791)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 10 19:54:33 PDT 2026


================
@@ -84,18 +84,33 @@ static bool isViableLoop(const CXXForRangeStmt &S, ASTContext &Context) {
   });
 }
 
+static bool isIteratingOverTemporary(const Expr *Init) {
----------------
zeyi2 wrote:

TBH this is not a "perfect" fix for all cases.

There are additional cases where the range expression depends on a temporary object through wrappers, but handling those would require a broader analysis of the range expression and would expand the scope of this change. IMHO those are better handled separately if we want to address them.

e.g.
```cpp
  #include <utility>
  #include <vector>
  std::vector<int> g(int a, int b, int c) { return {a, b, c}; }
  bool f(int a, int b, int c) {
    for (int i : std::move(g(a, b, c))) {
      if (i == 0)
        return true;
    }
    return false;
  }

```


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


More information about the cfe-commits mailing list