Menu

[derefInvalidIteratorRedundantCheck] false positive in do-while with break cond

DougCube
5 days ago
5 days ago
  • DougCube

    DougCube - 5 days ago

    This seems to be a false positive:
    (using 2.19.0)

    vector<int> vec;
    ...
    
    for(auto it = vec.begin(); it !=  vec.end();) {
        ...
        do {
            ...
            if(++it == vec.end()) break;
        } while(*it == 123);
        ...
    }
    

    warning: Either the condition 'it!=prev.end()' is redundant or there is
    possible dereference of an invalid iterator: it.
    [derefInvalidIteratorRedundantCheck] } while(
    it == 123);
    ^note: Assuming that condition 'it!=prev.end()' is not
    redundant for(auto it = vec.begin(); it != vec.end();) {
    ^note: Dereference of an invalid iterator
    } while(it == 123); ^

    -Doug

     

    Last edit: DougCube 5 days ago
  • CHR

    CHR - 5 days ago

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

     

Log in to post a comment.