Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,11 +1373,15 @@ void SymbolDatabase::createSymbolDatabaseEnums()

// find enumerators
for (const Token* tok = mTokenizer->list.front(); tok != mTokenizer->list.back(); tok = tok->next()) {
if (tok->tokType() != Token::eName)
const bool isVariable = (tok->tokType() == Token::eVariable && !tok->variable());
if (tok->tokType() != Token::eName && !isVariable)
continue;
const Enumerator * enumerator = findEnumerator(tok, tokensThatAreNotEnumeratorValues);
if (enumerator)
const_cast<Token *>(tok)->enumerator(enumerator);
if (enumerator) {
if (isVariable)
const_cast<Token*>(tok)->varId(0);
const_cast<Token*>(tok)->enumerator(enumerator);
}
}
}

Expand Down Expand Up @@ -4919,6 +4923,12 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
if (enumerator && !(enumerator->scope && enumerator->scope->enumClass))
return enumerator;

if (Token::simpleMatch(tok->astParent(), ".")) {
const Token* varTok = tok->astParent()->astOperand1();
if (varTok && varTok->variable() && varTok->variable()->type() && varTok->variable()->type()->classScope)
scope = varTok->variable()->type()->classScope;
}

for (std::vector<Scope *>::const_iterator s = scope->nestedList.cbegin(); s != scope->nestedList.cend(); ++s) {
enumerator = (*s)->findEnumerator(tokStr);

Expand Down Expand Up @@ -5434,6 +5444,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
if (rml)
valuetok = rml->previous();
}
if (vartok->isEnumerator())
valuetok = vartok;
const ValueType::MatchResult res = ValueType::matchParameter(valuetok->valueType(), var, funcarg);
if (res == ValueType::MatchResult::SAME)
++same;
Expand Down
6 changes: 3 additions & 3 deletions test/testplatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class TestPlatform : public TestFixture {
ASSERT_EQUALS(64, platform.long_long_bit);
}

void valid_config_file_1() {
void valid_config_file_1() const {
// Valid platform configuration with all possible values specified.
// Similar to the avr8 platform file.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
Expand Down Expand Up @@ -226,7 +226,7 @@ class TestPlatform : public TestFixture {
ASSERT_EQUALS(64, platform.long_long_bit);
}

void valid_config_file_2() {
void valid_config_file_2() const {
// Valid platform configuration with all possible values specified and
// char_bit > 8.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
Expand Down Expand Up @@ -296,7 +296,7 @@ class TestPlatform : public TestFixture {
TODO_ASSERT(!readPlatform(platform, xmldata));
}

void valid_config_file_4() {
void valid_config_file_4() const {
// Valid platform configuration with all possible values specified and
// set to 0.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
Expand Down
31 changes: 31 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(enum9);
TEST_CASE(enum10); // #11001
TEST_CASE(enum11);
TEST_CASE(enum12);

TEST_CASE(sizeOfType);

Expand Down Expand Up @@ -5480,6 +5481,22 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void enum12() {
GET_SYMBOL_DB_C("struct { enum E { E0 }; } t;\n"
"void f() {\n"
" if (t.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);
ASSERT_EQUALS(E0->value, 0);
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E0 )");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(e->enumerator(), E0);
}

void sizeOfType() {
// #7615 - crash in Symboldatabase::sizeOfType()
GET_SYMBOL_DB("enum e;\n"
Expand Down Expand Up @@ -6978,6 +6995,20 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(functok->function()->name() == "f");
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
}
{
GET_SYMBOL_DB("struct T { enum E { E0 }; } t; \n" // #11559
"void f(const void*, T::E) {}\n"
"void f(const int&, T::E) {}\n"
"void g() {\n"
" f(nullptr, t.E0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "f ( nullptr");
ASSERT(functok);
ASSERT(functok->function());
ASSERT(functok->function()->name() == "f");
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
}
}

void findFunction45() {
Expand Down