STL: fixed false positives in the new double-increment check when iterator shadows outer iterator
This commit is contained in:
parent
3340010376
commit
ef4ce6f46b
|
@ -865,7 +865,7 @@ void CheckStl::missingComparison()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &itName(tok2->str());
|
const unsigned int &iteratorId(tok2->varId());
|
||||||
const Token *incrementToken = 0;
|
const Token *incrementToken = 0;
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
// Parse loop..
|
// Parse loop..
|
||||||
|
@ -879,11 +879,11 @@ void CheckStl::missingComparison()
|
||||||
break;
|
break;
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
}
|
}
|
||||||
else if (tok3->str() == itName && Token::simpleMatch(tok3->next(), "++"))
|
else if (tok3->varId() == iteratorId && Token::simpleMatch(tok3->next(), "++"))
|
||||||
incrementToken = tok3;
|
incrementToken = tok3;
|
||||||
else if (tok3->str() == "++" && Token::simpleMatch(tok3->next(), itName.c_str()))
|
else if (tok3->str() == "++" && tok3->next() && tok3->next()->varId() == iteratorId)
|
||||||
incrementToken = tok3;
|
incrementToken = tok3;
|
||||||
else if (tok3->str() == itName && Token::Match(tok3->next(), "!=|=="))
|
else if (tok3->varId() == iteratorId && Token::Match(tok3->next(), "!=|=="))
|
||||||
incrementToken = 0;
|
incrementToken = 0;
|
||||||
}
|
}
|
||||||
if (incrementToken)
|
if (incrementToken)
|
||||||
|
|
|
@ -96,7 +96,8 @@ private:
|
||||||
|
|
||||||
// missing inner comparison when incrementing iterator inside loop
|
// missing inner comparison when incrementing iterator inside loop
|
||||||
TEST_CASE(missingInnerComparison1);
|
TEST_CASE(missingInnerComparison1);
|
||||||
TEST_CASE(missingInnerComparison2);
|
TEST_CASE(missingInnerComparison2); // no FP when there is comparison
|
||||||
|
TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const std::string &code)
|
void check(const std::string &code)
|
||||||
|
@ -1068,6 +1069,17 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void missingInnerComparison3()
|
||||||
|
{
|
||||||
|
check("void f(std::set<int> &ints) {\n"
|
||||||
|
" for (std::set<int>::iterator it = ints.begin(); it != ints.end(); ++it) {\n"
|
||||||
|
" for (std::set<int>::iterator it = ints2.begin(); it != ints2.end(); ++it)\n"
|
||||||
|
" { }\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestStl)
|
REGISTER_TEST(TestStl)
|
||||||
|
|
Loading…
Reference in New Issue