Fixed #8911 (Regression: False positive: Unassigned variable (alias))

This commit is contained in:
Daniel Marjamäki 2018-12-30 20:20:20 +01:00
parent 73fa941352
commit 6b49a784c5
2 changed files with 12 additions and 0 deletions

View File

@ -506,6 +506,8 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
}
} else if (var1->mType == Variables::reference) {
variables.alias(varid1, varid2, true);
} else if (var1->mType == Variables::standard && addressOf) {
variables.alias(varid1, varid2, true);
} else {
if ((var2->mType == Variables::pointer || var2->mType == Variables::pointerArray) && tok->strAt(1) == "[")
variables.readAliases(varid2, tok);

View File

@ -126,6 +126,7 @@ private:
TEST_CASE(localvaralias14); // ticket #5619
TEST_CASE(localvaralias15); // ticket #6315
TEST_CASE(localvaralias16);
TEST_CASE(localvaralias17); // ticket #8911
TEST_CASE(localvarasm);
TEST_CASE(localvarstatic);
TEST_CASE(localvarextern);
@ -3185,6 +3186,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvaralias17() {
functionVariableUsage("void f() {\n"
" int x;\n"
" unknown_type p = &x;\n"
" *p = 9;\n"
"}", "test.c");
ASSERT_EQUALS("", errout.str());
}
void localvarasm() {
functionVariableUsage("void foo(int &b)\n"