Skip to content

Commit 94b6c87

Browse files
Fix #11728 FP unreadVariable with brace-init (#5075)
1 parent 211ab3d commit 94b6c87

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/fwdanalysis.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,6 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
501501
const bool pure = false;
502502
const bool followVar = false;
503503
for (const Token *tok = startToken; tok; tok = tok->previous()) {
504-
if (tok->str() == "{" && tok->scope()->type == Scope::eFunction && !(tok->astParent() && tok->astParent()->str() == ","))
505-
break;
506504

507505
if (Token::Match(tok, "%name% (") && !Token::Match(tok, "if|while|for")) {
508506
// Is argument passed by reference?

test/testunusedvar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class TestUnusedVar : public TestFixture {
161161
TEST_CASE(localvaralias18); // ticket #9234 - iterator
162162
TEST_CASE(localvaralias19); // ticket #9828
163163
TEST_CASE(localvaralias20); // ticket #10966
164+
TEST_CASE(localvaralias21);
164165
TEST_CASE(localvarasm);
165166
TEST_CASE(localvarstatic);
166167
TEST_CASE(localvarextern);
@@ -4926,6 +4927,18 @@ class TestUnusedVar : public TestFixture {
49264927
errout.str());
49274928
}
49284929

4930+
void localvaralias21() { // #11728
4931+
functionVariableUsage("void f(int i) {\n"
4932+
" bool b = true;\n"
4933+
" bool* p = &b;\n"
4934+
" int j{};\n"
4935+
" if (i)\n"
4936+
" b = false;\n"
4937+
" if (*p) {}\n"
4938+
"}\n");
4939+
ASSERT_EQUALS("", errout.str());
4940+
}
4941+
49294942
void localvarasm() {
49304943

49314944
functionVariableUsage("void foo(int &b)\n"

0 commit comments

Comments
 (0)