Skip to content

Commit

Permalink
Fix #12567 valueFlowBailoutIncompleteVar with nested enum (#6224)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Apr 3, 2024
1 parent f94a60d commit edfcc31
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5246,17 +5246,21 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
if (tok1->strAt(-1) == "::")
scope = &scopeList.front();
else {
// FIXME search base class here

const Scope* temp = nullptr;
if (scope)
temp = scope->findRecordInNestedList(tok1->str());
// find first scope
while (scope && scope->nestedIn) {
if (!temp)
temp = scope->nestedIn->findRecordInNestedList(tok1->str());
if (!temp && scope->functionOf)
if (!temp && scope->functionOf) {
temp = scope->functionOf->findRecordInNestedList(tok1->str());
const Scope* nested = scope->functionOf->nestedIn;
while (!temp && nested) {
temp = nested->findRecordInNestedList(tok1->str());
nested = nested->nestedIn;
}
}
if (!temp)
temp = findEnumScopeInBase(scope, tok1->str());
if (temp) {
Expand Down
46 changes: 46 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6310,6 +6310,52 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
}
{
GET_SYMBOL_DB("namespace ns {\n" // #12567
" struct S1 {\n"
" enum E { E1 } e;\n"
" };\n"
" struct S2 {\n"
" static void f();\n"
" };\n"
"}\n"
"void ns::S2::f() {\n"
" S1 s;\n"
" s.e = S1::E1;\n"
"}\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 3);
const Enumerator* E1 = it->findEnumerator("E1");
ASSERT(E1 && E1->value_known && E1->value == 0);
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E1 ;");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E1, e->enumerator());
}
{
GET_SYMBOL_DB("namespace N {\n"
" struct S1 {\n"
" enum E { E1 } e;\n"
" };\n"
" namespace O {\n"
" struct S2 {\n"
" static void f();\n"
" };\n"
" }\n"
"}\n"
"void N::O::S2::f() {\n"
" S1 s;\n"
" s.e = S1::E1;\n"
"}\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 3);
const Enumerator* E1 = it->findEnumerator("E1");
ASSERT(E1 && E1->value_known && E1->value == 0);
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E1 ;");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E1, e->enumerator());
}
}

void sizeOfType() {
Expand Down

0 comments on commit edfcc31

Please sign in to comment.