Fixed false positive with range-based for-loop (#7078)

This commit is contained in:
PKEuS 2015-10-28 16:37:46 +01:00
parent a0ff992c4a
commit 963008089d
2 changed files with 12 additions and 1 deletions

View File

@ -60,7 +60,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
if (i->isThrow())
continue;
if (i->nameToken()->strAt(1) == "(" || i->nameToken()->strAt(1) == "{")
if (i->nameToken()->strAt(1) == "(" || i->nameToken()->strAt(1) == "{" || i->nameToken()->strAt(1) == ":")
continue;
if (Token::Match(i->nameToken(), "%name% =")) { // Variable is initialized, but Rhs might be not

View File

@ -68,6 +68,7 @@ private:
TEST_CASE(uninitvar_ternaryexpression); // #4683
TEST_CASE(uninitvar_pointertoarray);
TEST_CASE(uninitvar_cpp11ArrayInit); // #7010
TEST_CASE(uninitvar_rangeBasedFor); // #7078
TEST_CASE(trac_4871);
TEST_CASE(syntax_error); // Ticket #5073
@ -3651,6 +3652,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void uninitvar_rangeBasedFor() { // #7078
checkUninitVar("void function(Entry& entry) {\n"
" for (auto* expr : entry.exprs) {\n"
" expr->operate();\n"
" expr->operate();\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void trac_4871() { // #4871
checkUninitVar("void pickup(int a) {\n"
"bool using_planner_action;\n"