Menu

False positive: mismatchingContainerExpression

2020-11-25
2020-11-26
  • Simon Martin

    Simon Martin - 2020-11-25

    Hi,

    cppcheck reports an incorrect mismatchingContainerExpression warning for the following code, which has a member function called end().

    class foo
    {
      int m_bar;
    
    public:
      foo(int bar) : m_bar(bar) {}
    
      int end() { return m_bar; }
    };
    
    
    int main()
    {
      foo first(1);
      foo second(2);
      if (first.end() == second.end())
        return 1;
    
      return 0;
    }
    

    Warning:

    end.cxx:16:7: warning: Iterators to containers from different expressions 'first' and 'second' are used together. [mismatchingContainerExpression]
      if (first.end() == second.end())
    

    Thanks

     
  • Daniel Marjamäki

    Ouch! I have created this ticket:
    https://trac.cppcheck.net/ticket/10012#ticket

     

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.