Fix #12157 SymbolDatabase: Token::type() is not set properly when inn… (#5635)

…er enum has same name as outer class
This commit is contained in:
chrchr-github 2023-11-07 19:57:45 +01:00 committed by GitHub
parent c1aed9681d
commit d3d70dcc4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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) {

View File

@ -5975,6 +5975,27 @@ private:
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() {