Skip to content

Commit 023e79b

Browse files
Fix #11459 uninitvar false positive (#5011)
* Fix #11459 uninitvar false positive * Format
1 parent 9ea223b commit 023e79b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4959,6 +4959,11 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
49594959
if (varTok && varTok->variable() && varTok->variable()->type() && varTok->variable()->type()->classScope)
49604960
scope = varTok->variable()->type()->classScope;
49614961
}
4962+
else if (Token::simpleMatch(tok->astParent(), "[")) {
4963+
const Token* varTok = tok->astParent()->previous();
4964+
if (varTok && varTok->variable() && varTok->variable()->scope() && Token::simpleMatch(tok->astParent()->astOperand1(), "::"))
4965+
scope = varTok->variable()->scope();
4966+
}
49624967

49634968
for (std::vector<Scope *>::const_iterator s = scope->nestedList.cbegin(); s != scope->nestedList.cend(); ++s) {
49644969
enumerator = (*s)->findEnumerator(tokStr);

test/testuninitvar.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5998,6 +5998,21 @@ class TestUninitVar : public TestFixture {
59985998
" if ((cp = getenv(envar)) != NULL) {}\n"
59995999
"}\n");
60006000
ASSERT_EQUALS("", errout.str());
6001+
6002+
// #11459
6003+
valueFlowUninit("struct S {\n"
6004+
" enum E { N = 3 };\n"
6005+
" static const int A[N];\n"
6006+
" static void f();\n"
6007+
"};\n"
6008+
"const int S::A[N] = { 0, 1, 2 };\n"
6009+
"void S::f() {\n"
6010+
" int tmp[N];\n"
6011+
" for (int i = 0; i < N; i++)\n"
6012+
" tmp[i] = 0;\n"
6013+
" if (tmp[0]) {}\n"
6014+
"}\n");
6015+
ASSERT_EQUALS("", errout.str());
60016016
}
60026017

60036018
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value

0 commit comments

Comments
 (0)