Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-analyzer-alpha.cplusplus.MismatchedIterator false positive with container insertion #132010

Closed
firewave opened this issue Mar 19, 2025 · 1 comment · Fixed by #132596
Closed
Labels
clang:static analyzer false-positive Warning fires when it should not

Comments

@firewave
Copy link

#include <list>
#include <unordered_set>

void f()
{
    std::list<int> l;
    std::unordered_set<int> us;
    us.insert(l.cbegin(), l.cend());
}
<source>:8:5: warning: Container accessed using foreign iterator argument [clang-analyzer-alpha.cplusplus.MismatchedIterator]
    8 |     us.insert(l.cbegin(), l.cend());
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:8:5: note: Container accessed using foreign iterator argument
    8 |     us.insert(l.cbegin(), l.cend());
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://godbolt.org/z/arhEMh6Go

@firewave firewave added clang:static analyzer false-positive Warning fires when it should not labels Mar 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 19, 2025

@llvm/issue-subscribers-clang-static-analyzer

Author: Oliver Stöneberg (firewave)

```cpp #include <list> #include <unordered_set>

void f()
{
std::list<int> l;
std::unordered_set<int> us;
us.insert(l.cbegin(), l.cend());
}


<source>:8:5: warning: Container accessed using foreign iterator argument [clang-analyzer-alpha.cplusplus.MismatchedIterator]
8 | us.insert(l.cbegin(), l.cend());
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:8:5: note: Container accessed using foreign iterator argument
8 | us.insert(l.cbegin(), l.cend());
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://godbolt.org/z/arhEMh6Go
</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer false-positive Warning fires when it should not
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants