Fix #11728 FP unreadVariable with brace-init (#5075)

This commit is contained in:
chrchr-github 2023-05-23 20:21:02 +02:00 committed by GitHub
parent 211ab3dd63
commit 94b6c87049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -501,8 +501,6 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
const bool pure = false;
const bool followVar = false;
for (const Token *tok = startToken; tok; tok = tok->previous()) {
if (tok->str() == "{" && tok->scope()->type == Scope::eFunction && !(tok->astParent() && tok->astParent()->str() == ","))
break;
if (Token::Match(tok, "%name% (") && !Token::Match(tok, "if|while|for")) {
// Is argument passed by reference?

View File

@ -161,6 +161,7 @@ private:
TEST_CASE(localvaralias18); // ticket #9234 - iterator
TEST_CASE(localvaralias19); // ticket #9828
TEST_CASE(localvaralias20); // ticket #10966
TEST_CASE(localvaralias21);
TEST_CASE(localvarasm);
TEST_CASE(localvarstatic);
TEST_CASE(localvarextern);
@ -4926,6 +4927,18 @@ private:
errout.str());
}
void localvaralias21() { // #11728
functionVariableUsage("void f(int i) {\n"
" bool b = true;\n"
" bool* p = &b;\n"
" int j{};\n"
" if (i)\n"
" b = false;\n"
" if (*p) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvarasm() {
functionVariableUsage("void foo(int &b)\n"