diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 19da2bde2..ecd5f5abb 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1157,7 +1157,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int if (initif && initelse) return true; - if (initif || initelse) + if (initif || initelse || possibleInitElse) ++number_of_if; } } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index de0b3434a..23a45e9c3 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1909,6 +1909,14 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" + " int a=0, b;\n" + " if (x) { }\n" + " else if (y==2) { a=1; b=2; }\n" + " if (a) { ++b; }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // asm checkUninitVar2("void f() {\n" " int x;\n"