Menu

false positive: eraseDereference: Iterator 'it' used after element has been erased.

2021-01-20
2021-01-29
  • Steffen Brauer

    Steffen Brauer - 2021-01-20

    TEST_CASE("erase from set, return result from erase", "[cppcheck][false-positive]")
    {
    static std::set<int> a_set;
    for (auto it = a_set.begin(); it != a_set.end(); ++it)
    if (*it == 42)
    return a_set.erase(it);
    return a_set.end();
    }</int>

    The line "return a_set.erase(it);" triggers the error.

     
  • CHR

    CHR - 2021-01-29

    Thanks. I have created a ticket here: https://trac.cppcheck.net/ticket/10151

     

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.