Skip to content

Commit

Permalink
Fix #12157 SymbolDatabase: Token::type() is not set properly when inn… (
Browse files Browse the repository at this point in the history
#5635)

…er enum has same name as outer class
  • Loading branch information
chrchr-github committed Nov 7, 2023
1 parent c1aed96 commit d3d70dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5086,9 +5086,13 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
else {
// FIXME search base class here

const Scope* temp = nullptr;
if (scope)
temp = scope->findRecordInNestedList(tok1->str());
// find first scope
while (scope && scope->nestedIn) {
const Scope* temp = scope->nestedIn->findRecordInNestedList(tok1->str());
if (!temp)
temp = scope->nestedIn->findRecordInNestedList(tok1->str());
if (!temp && scope->functionOf)
temp = scope->functionOf->findRecordInNestedList(tok1->str());
if (temp) {
Expand Down
21 changes: 21 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5975,6 +5975,27 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
}
{
GET_SYMBOL_DB("struct S {\n"
" enum class E {\n"
" A, D\n"
" } e = E::D;\n"
"};\n"
"struct E {\n"
" enum { A, B, C, D };\n"
"};\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 2);
ASSERT_EQUALS(it->className, "E");
ASSERT(it->nestedIn);
ASSERT_EQUALS(it->nestedIn->className, "S");
const Enumerator* D = it->findEnumerator("D");
ASSERT(D && D->value_known && D->value == 1);
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "D ;");
ASSERT(tok && tok->enumerator());
ASSERT_EQUALS(D, tok->enumerator());
}
}

void sizeOfType() {
Expand Down

0 comments on commit d3d70dc

Please sign in to comment.