Set enum ValueType for :: (#5298)

This commit is contained in:
chrchr-github 2023-08-07 21:40:33 +02:00 committed by GitHub
parent 072212e708
commit 610777d586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -6414,8 +6414,12 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
if (it != typeScope->varlist.end()) if (it != typeScope->varlist.end())
var = &*it; var = &*it;
} }
if (var) if (var) {
setValueType(parent, *var); setValueType(parent, *var);
return;
}
if (const Enumerator* enu = parent->astOperand2()->enumerator())
setValueType(parent, *enu);
return; return;
} }

View File

@ -384,6 +384,7 @@ private:
TEST_CASE(enum10); // #11001 TEST_CASE(enum10); // #11001
TEST_CASE(enum11); TEST_CASE(enum11);
TEST_CASE(enum12); TEST_CASE(enum12);
TEST_CASE(enum13);
TEST_CASE(sizeOfType); TEST_CASE(sizeOfType);
@ -5701,6 +5702,23 @@ private:
ASSERT_EQUALS(e->enumerator(), E0); ASSERT_EQUALS(e->enumerator(), E0);
} }
void enum13() {
GET_SYMBOL_DB("struct S { enum E { E0, E1 }; };\n"
"void f(bool b) {\n"
" auto e = b ? S::E0 : S::E1;\n"
"}\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 2);
const Enumerator* E1 = it->findEnumerator("E1");
ASSERT(E1 && E1->value_known);
ASSERT_EQUALS(E1->value, 1);
const Token* const a = Token::findsimplematch(tokenizer.tokens(), "auto");
ASSERT(a && a->valueType());
TODO_ASSERT(E1->scope == a->valueType()->typeScope);
ASSERT_EQUALS(a->valueType()->type, ValueType::INT);
}
void sizeOfType() { void sizeOfType() {
// #7615 - crash in Symboldatabase::sizeOfType() // #7615 - crash in Symboldatabase::sizeOfType()
GET_SYMBOL_DB("enum e;\n" GET_SYMBOL_DB("enum e;\n"