diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index 29cea75ba..ff0ee0e16 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -260,6 +260,11 @@ void ExecutionPath::checkScope(const Token *tok, std::list &che if (tok->str() != "switch") { + for (const Token *tok3 = tok; tok3 && tok3 != tok2; tok3 = tok3->next()) + { + if (tok3->varId()) + ExecutionPath::bailOutVar(checks, tok3->varId()); + } check->parseLoopBody(tok2->next(), checks); } diff --git a/test/testother.cpp b/test/testother.cpp index 2cf84ec19..5e5061e80 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1769,6 +1769,16 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: k\n", errout.str()); + checkUninitVar("enum ABCD { A, B, C, D };\n" + "\n" + "static void f(char *str ) {\n" + " enum ABCD i;\n" + " for (i = 0; i < D; i++) {\n" + " str[i] = 0;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // while.. checkUninitVar("int f()\n" "{\n"