Fixed #9123 (False positive: uninitialized variable)
This commit is contained in:
parent
0725c2290c
commit
c029d5150c
|
@ -923,6 +923,8 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, Alloc alloc
|
|||
uninitStructMemberError(tok, tok->str() + "." + membervar);
|
||||
else if (Token::Match(tok, "%var% ="))
|
||||
break;
|
||||
else if (Token::Match(tok->previous(), "[(,&]"))
|
||||
break;
|
||||
} else if (tok->str() == ";" || (indent==0 && tok->str() == ","))
|
||||
break;
|
||||
else if (tok->str() == "(")
|
||||
|
|
|
@ -70,6 +70,7 @@ private:
|
|||
TEST_CASE(uninitvar8); // ticket #6230
|
||||
TEST_CASE(uninitvar9); // ticket #6424
|
||||
TEST_CASE(uninitvar10); // ticket #9467
|
||||
TEST_CASE(uninitvar11); // ticket #9123
|
||||
TEST_CASE(uninitvar_unconditionalTry);
|
||||
TEST_CASE(uninitvar_funcptr); // #6404
|
||||
TEST_CASE(uninitvar_operator); // #6680
|
||||
|
@ -2725,6 +2726,16 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar11() { // 9123
|
||||
const char code[] = "bool get(int &var);\n"
|
||||
"void foo () {\n"
|
||||
" int x;\n"
|
||||
" x = get(x) && x;\n"
|
||||
"}";
|
||||
checkUninitVar(code, "test.cpp");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar_unconditionalTry() {
|
||||
// Unconditional scopes and try{} scopes
|
||||
checkUninitVar("int f() {\n"
|
||||
|
|
Loading…
Reference in New Issue