Fixed #4684 (cppcheck crash in template function call.)

This commit is contained in:
Alexander Mai 2013-03-29 19:29:23 +01:00 committed by Daniel Marjamäki
parent 4fc92f4c27
commit b9c27699b3
2 changed files with 17 additions and 1 deletions

View File

@ -580,7 +580,7 @@ void CheckStl::pushback()
// Iterator becomes invalid after reserve, resize, insert, push_back or push_front..
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
for (const Token* tok = scope->classStart->next(); tok && tok != scope->classEnd; tok = tok->next()) {
if (!Token::simpleMatch(tok, "vector <"))
continue;

View File

@ -123,6 +123,7 @@ private:
TEST_CASE(autoPointer);
TEST_CASE(uselessCalls);
TEST_CASE(stabilityOfChecks); // #4684 cppcheck crash in template function call
}
@ -2230,6 +2231,21 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
}
void stabilityOfChecks() {
// Stability test: 4684 cppcheck crash in template function call.
check("template<class T>\n"
"class EffectivityRangeData {};\n"
"template<class T>\n"
"class EffectivityRange {\n"
" void unite() {\n"
" x < vector < EffectivityRangeData<int >> >();\n"
" EffectivityRange<int> er;\n"
" }\n"
" void shift() { EffectivityRangeData<int>::iterator it; } \n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestStl)