Fixed false positive with range-based for-loop (#7078)
This commit is contained in:
parent
a0ff992c4a
commit
963008089d
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue