Skip to content

Commit edfcc31

Browse files
Fix #12567 valueFlowBailoutIncompleteVar with nested enum (#6224)
1 parent f94a60d commit edfcc31

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,17 +5246,21 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
52465246
if (tok1->strAt(-1) == "::")
52475247
scope = &scopeList.front();
52485248
else {
5249-
// FIXME search base class here
5250-
52515249
const Scope* temp = nullptr;
52525250
if (scope)
52535251
temp = scope->findRecordInNestedList(tok1->str());
52545252
// find first scope
52555253
while (scope && scope->nestedIn) {
52565254
if (!temp)
52575255
temp = scope->nestedIn->findRecordInNestedList(tok1->str());
5258-
if (!temp && scope->functionOf)
5256+
if (!temp && scope->functionOf) {
52595257
temp = scope->functionOf->findRecordInNestedList(tok1->str());
5258+
const Scope* nested = scope->functionOf->nestedIn;
5259+
while (!temp && nested) {
5260+
temp = nested->findRecordInNestedList(tok1->str());
5261+
nested = nested->nestedIn;
5262+
}
5263+
}
52605264
if (!temp)
52615265
temp = findEnumScopeInBase(scope, tok1->str());
52625266
if (temp) {

test/testsymboldatabase.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,6 +6310,52 @@ class TestSymbolDatabase : public TestFixture {
63106310
ASSERT(e && e->enumerator());
63116311
ASSERT_EQUALS(E0, e->enumerator());
63126312
}
6313+
{
6314+
GET_SYMBOL_DB("namespace ns {\n" // #12567
6315+
" struct S1 {\n"
6316+
" enum E { E1 } e;\n"
6317+
" };\n"
6318+
" struct S2 {\n"
6319+
" static void f();\n"
6320+
" };\n"
6321+
"}\n"
6322+
"void ns::S2::f() {\n"
6323+
" S1 s;\n"
6324+
" s.e = S1::E1;\n"
6325+
"}\n");
6326+
ASSERT(db != nullptr);
6327+
auto it = db->scopeList.begin();
6328+
std::advance(it, 3);
6329+
const Enumerator* E1 = it->findEnumerator("E1");
6330+
ASSERT(E1 && E1->value_known && E1->value == 0);
6331+
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E1 ;");
6332+
ASSERT(e && e->enumerator());
6333+
ASSERT_EQUALS(E1, e->enumerator());
6334+
}
6335+
{
6336+
GET_SYMBOL_DB("namespace N {\n"
6337+
" struct S1 {\n"
6338+
" enum E { E1 } e;\n"
6339+
" };\n"
6340+
" namespace O {\n"
6341+
" struct S2 {\n"
6342+
" static void f();\n"
6343+
" };\n"
6344+
" }\n"
6345+
"}\n"
6346+
"void N::O::S2::f() {\n"
6347+
" S1 s;\n"
6348+
" s.e = S1::E1;\n"
6349+
"}\n");
6350+
ASSERT(db != nullptr);
6351+
auto it = db->scopeList.begin();
6352+
std::advance(it, 3);
6353+
const Enumerator* E1 = it->findEnumerator("E1");
6354+
ASSERT(E1 && E1->value_known && E1->value == 0);
6355+
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E1 ;");
6356+
ASSERT(e && e->enumerator());
6357+
ASSERT_EQUALS(E1, e->enumerator());
6358+
}
63136359
}
63146360

63156361
void sizeOfType() {

0 commit comments

Comments
 (0)