Fixed #7650 (SymbolDatabase: Wrong Token::type(), enum and class with same name)

This commit is contained in:
Robert Reif 2016-08-02 23:30:46 +02:00 committed by Daniel Marjamäki
parent 908e1b991e
commit b9030bcfcd
2 changed files with 32 additions and 2 deletions

View File

@ -3496,8 +3496,16 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty
break;
}
if (type->enclosingScope == parent)
return &(*type);
if (type->enclosingScope == parent) {
if (typeTok->strAt(-1) == "enum") {
if (type->classDef->str() == "enum")
return &(*type);
} else if (typeTok->strAt(-1) == "struct") {
if (type->classDef->str() == "struct")
return &(*type);
} else
return &(*type);
}
}
// type has a namespace

View File

@ -182,6 +182,7 @@ private:
TEST_CASE(functionArgs2);
TEST_CASE(functionArgs3);
TEST_CASE(functionArgs4);
TEST_CASE(functionArgs5); // #7650
TEST_CASE(namespaces1);
TEST_CASE(namespaces2);
@ -1574,6 +1575,27 @@ private:
}
}
void functionArgs5() { // #7650
GET_SYMBOL_DB("class ABC {};\n"
"class Y {\n"
" enum ABC {A,B,C};\n"
" void f(enum ABC abc) {}\n"
"};");
ASSERT_EQUALS(true, db != nullptr);
if (db) {
const Token *f = Token::findsimplematch(tokenizer.tokens(), "f ( enum");
ASSERT_EQUALS(true, f && f->function());
if (f && f->function()) {
const Function *func = f->function();
ASSERT_EQUALS(true, func->argumentList.size() == 1 && func->argumentList.front().type());
if (func->argumentList.size() == 1 && func->argumentList.front().type()) {
const Type * type = func->argumentList.front().type();
ASSERT_EQUALS(true, type->classDef->str() == "enum");
}
}
}
}
void namespaces1() {
GET_SYMBOL_DB("namespace fred {\n"
" namespace barney {\n"