Menu

cppcheck complains about dereferencing iterators in an array of iterators

Tal
2024-11-20
2024-11-20
  • Tal

    Tal - 2024-11-20

    cppcheck complains about dereferencing iterators in an array of iterators:

    #include <vector>
    
    std::vector<int>::const_iterator f()
    {
        const std::vector<int> v = {1, 2, 3, 4};
        const std::vector<int>::const_iterator a[2] = { v.begin(), v.end() };
        return *a[1];
    }
    

    Yields the error:

    [test.cpp:7]: (error) The iterator 'a' is invalid before being assigned. Dereferencing or comparing it with another iterator is invalid operation.
    
     
  • CHR

    CHR - 2024-11-20

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

     
    • Tal

      Tal - 2024-11-20

      thanks!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.