Menu

mismatchingContainerExpression false positive

1 day ago
10 hours ago
  • Pontus Eriksson

    Hello
    Using Cppcheck-2.21.0 I get a warning here:

    #include <algorithm>
    #include <cassert>
    #include <vector>
    
    int main()
    {
        std::vector<int> v { 1, 1, 2, 3, 3 };
        std::ranges::sort(v);
        v.erase(std::ranges::unique(v).begin(), v.end());
        assert((v == std::vector<int> { 1, 2, 3 }));
    }
    

    warning: Iterators to containers from different expressions 'std::ranges::unique(v)' and 'v' are used together. [mismatchingContainerExpression]
    v.erase(std::ranges::unique(v).begin(), v.end());
    ^

     
  • CHR

    CHR - 10 hours ago

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14908

     

Log in to post a comment.

Auth0 Logo