diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 0329b66da..b0497ac70 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1909,6 +1909,9 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, } if (Token::simpleMatch(tok2->astParent(), ":") && tok2->astParent()->astParent() && Token::simpleMatch(tok2->astParent()->astParent()->previous(), "for (")) { + // TODO: Check if container is empty or not + if (astIsLHS(tok2)) + return true; const Token * varTok = tok2->astParent()->previous(); if (!varTok) return false; diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d431f1d8a..65c1da3b5 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1528,8 +1528,6 @@ void CheckUninitVar::valueFlowUninit() continue; if (v->indirect > 1 || v->indirect < 0) continue; - if (v->indirect == 0 && !isVariableUsage(tok, tok->valueType() && tok->valueType()->pointer > 0, NO_ALLOC)) - continue; bool uninitderef = false; if (tok->variable()) { bool unknown; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 2aebecf42..7948632f2 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4646,6 +4646,16 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + valueFlowUninit("X f() {\n" + " if (!itemList.empty()) {\n" + " X* item;\n" + " for(item: itemList) {}\n" + " return *item;\n" + " }\n" + " return X{};\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // macro_for.. valueFlowUninit("int foo()\n" "{\n"