From b9030bcfcd48785f2d1b5506823a2c0e1e7ea52b Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 2 Aug 2016 23:30:46 +0200 Subject: [PATCH] Fixed #7650 (SymbolDatabase: Wrong Token::type(), enum and class with same name) --- lib/symboldatabase.cpp | 12 ++++++++++-- test/testsymboldatabase.cpp | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 308ab73d4..4014d885e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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 diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 431e6da85..4bb8cc9f5 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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"