diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 362c9cdaa..69df566b9 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4959,6 +4959,11 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::setvariable() && varTok->variable()->type() && varTok->variable()->type()->classScope) scope = varTok->variable()->type()->classScope; } + else if (Token::simpleMatch(tok->astParent(), "[")) { + const Token* varTok = tok->astParent()->previous(); + if (varTok && varTok->variable() && varTok->variable()->scope() && Token::simpleMatch(tok->astParent()->astOperand1(), "::")) + scope = varTok->variable()->scope(); + } for (std::vector::const_iterator s = scope->nestedList.cbegin(); s != scope->nestedList.cend(); ++s) { enumerator = (*s)->findEnumerator(tokStr); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 277fcd2d7..fc3220892 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -5998,6 +5998,21 @@ private: " if ((cp = getenv(envar)) != NULL) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #11459 + valueFlowUninit("struct S {\n" + " enum E { N = 3 };\n" + " static const int A[N];\n" + " static void f();\n" + "};\n" + "const int S::A[N] = { 0, 1, 2 };\n" + "void S::f() {\n" + " int tmp[N];\n" + " for (int i = 0; i < N; i++)\n" + " tmp[i] = 0;\n" + " if (tmp[0]) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value