diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index dde0b7ddf7e..e8832cb634a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5984,6 +5984,9 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen const Function* SymbolDatabase::findFunction(const Token* const tok) const { + if (tok->tokType() == Token::Type::eEnumerator) + return nullptr; + // find the scope this function is in const Scope *currScope = tok->scope(); while (currScope && currScope->isExecutable()) { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index f24c4455767..e39eea4f3ae 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -521,6 +521,7 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(findFunction55); // #13004 TEST_CASE(findFunction56); TEST_CASE(findFunction57); + TEST_CASE(findFunction58); // #13310 TEST_CASE(findFunctionRef1); TEST_CASE(findFunctionContainer); TEST_CASE(findFunctionExternC); @@ -8374,6 +8375,19 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(T->function()->tokenDef->linenr(), 6); } + void findFunction58() { // #13310 + GET_SYMBOL_DB("class C {\n" + " enum class abc : uint8_t {\n" + " a,b,c\n" + " };\n" + " void a();\n" + "};\n"); + const Token *a1 = Token::findsimplematch(tokenizer.tokens(), "a ,"); + ASSERT(a1 && !a1->function()); + const Token *a2 = Token::findsimplematch(tokenizer.tokens(), "a ("); + ASSERT(a2 && a2->function()); + } + void findFunctionRef1() { GET_SYMBOL_DB("struct X {\n" " const std::vector getInts() const & { return mInts; }\n"