Uninitialized variables: Fixed false positives caused by recent improvement when variable is potentially initialized in else block.
This commit is contained in:
parent
c56e2e7cf9
commit
481fa532a8
|
@ -1157,7 +1157,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
||||||
if (initif && initelse)
|
if (initif && initelse)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (initif || initelse)
|
if (initif || initelse || possibleInitElse)
|
||||||
++number_of_if;
|
++number_of_if;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1909,6 +1909,14 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
// asm
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue