Fixed #4394 (FP: Variable 'a' is not assigned a value)

This commit is contained in:
Daniel Marjamäki 2013-02-20 17:43:16 +01:00
parent e46f0cf124
commit bce99a9e2f
2 changed files with 17 additions and 3 deletions

View File

@ -427,9 +427,13 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
}
tok = tok->next();
if (Token::Match(tok, "&| %var%") ||
Token::Match(tok, "( const| struct|union| %type% *| ) &| %var%") ||
Token::Match(tok, "( const| struct|union| %type% *| ) ( &| %var%") ||
if (Token::Match(tok, "( const| struct|union| %type% * ) ( ("))
tok = tok->link()->next();
if (Token::Match(tok, "( [(<] const| struct|union| %type% *| [>)]"))
tok = tok->next();
if (Token::Match(tok, "(| &| %var%") ||
Token::Match(tok->next(), "< const| struct|union| %type% *| > ( &| %var%")) {
bool addressOf = false;

View File

@ -103,6 +103,7 @@ private:
TEST_CASE(localvaralias9); // ticket #1996
TEST_CASE(localvaralias10); // ticket #2004
TEST_CASE(localvaralias11); // ticket #4423 - iterator
TEST_CASE(localvaralias12); // ticket #4394
TEST_CASE(localvarasm);
TEST_CASE(localvarstatic);
TEST_CASE(localvarextern);
@ -2727,6 +2728,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvaralias12() { // #4394
functionVariableUsage("void f(void) {\n"
" int a[4];\n"
" int *b = (int*)((int*)a+1);\n"
" x(b);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarasm() {
functionVariableUsage("void foo(int &b)\n"
"{\n"