[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 19 01:55:15 PDT 2024


================
@@ -1710,4 +1710,25 @@ TEST_F(TopTest, ForRangeStmtConverges) {
                 // analysis converged.
               });
 }
+
+TEST_F(TopTest, ForRangeStmtHasFlowCondition) {
+  std::string Code = R"(
+    #include <array>
+    void target(bool Foo) {
+      std::array<int, 5> t;
+      for (auto& i : t) {
+        (void)0;
+        /*[[p1]]*/
+      }
+    }
----------------
martinboehme wrote:

```suggestion
    #include <initializer_list>
    void target() {
      for (auto& i : {1, 2}) {
        (void)0;
        /*[[p1]]*/
      }
    }
```

Try to keep code snippets as simple as possible:

*  I don't think `Foo` is needed here?
*  An `initializer_list` is probably the simplest thing you can use to iterate over (it doesn't matter specifically what you're iterating over, right?)

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


More information about the cfe-commits mailing list