Set enumerator in ctor init list (refs #10045) (#5599)

This commit is contained in:
chrchr-github 2023-10-28 13:51:52 +02:00 committed by GitHub
parent e8671c92cc
commit f6fb3334f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -5106,6 +5106,15 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
}
}
} else { // unqualified name
if (tok->scope()->type == Scope::eGlobal) {
const Token* astTop = tok->astTop();
if (Token::simpleMatch(astTop, ":") && Token::simpleMatch(astTop->astOperand1(), "(")) { // ctor init list
const Token* ctor = astTop->astOperand1()->previous();
if (ctor && ctor->function() && ctor->function()->nestedIn)
scope = ctor->function()->nestedIn;
}
}
const Enumerator * enumerator = scope->findEnumerator(tokStr);
if (enumerator && !(enumerator->scope && enumerator->scope->enumClass))

View File

@ -5943,11 +5943,33 @@ private:
std::advance(it, 2);
const Enumerator* E0 = it->findEnumerator("E0");
ASSERT(E0 && E0->value_known && E0->value == 0);
std::advance(it, 1);
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E0 ;");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
}
{
GET_SYMBOL_DB("struct S {\n"
" enum E { E0 };\n"
" void f(int i);\n"
" S();\n"
" int m;\n"
"};\n"
"S::S() : m(E0) {}\n"
"void S::f(int i) {\n"
" if (i != E0) {}\n"
"}\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 2);
const Enumerator* E0 = it->findEnumerator("E0");
ASSERT(E0 && E0->value_known && E0->value == 0);
const Token* e = Token::findsimplematch(tokenizer.tokens(), "E0 )");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
e = Token::findsimplematch(e->next(), "E0 )");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
}
}
void sizeOfType() {