Issue 132649
Summary `clang-analyzer-alpha.cplusplus.MismatchedIterator` false positive
Labels clang:static analyzer, false-positive
Assignees
Reporter firewave
    ```cpp
#include <list>

class C
{
public:
    C(const std::list<int> &files)
        : mFiles(files)
    {
        mItNextFile = mFiles.begin();
    }

 bool func() {
        if (mItNextFile != mFiles.end()) {
 ++mItNextFile;
            return true;
        }

        return false;
    }

private:
    const std::list<int> &mFiles;
 std::list<int>::const_iterator mItNextFile;
};

static void f(C *c)
{
 while (c->func()) {}
}
```

```
<source>:13:13: warning: Iterators of different containers used where the same container is expected [clang-analyzer-alpha.cplusplus.MismatchedIterator]
   13 |         if (mItNextFile != mFiles.end()) {
      |             ^
<source>:28:5: note: Loop condition is true.  Entering loop body
   28 |     while (c->func()) {}
      |     ^
<source>:28:12: note: Calling 'C::func'
   28 |     while (c->func()) {}
      |            ^~~~~~~~~
<source>:13:13: note: Iterators of different containers used where the same container is expected
   13 | if (mItNextFile != mFiles.end()) {
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
```

https://godbolt.org/z/PjfExYP4r
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to