Skip to content

Commit 61b75e6

Browse files
authored
Fix #13310: SymbolDatabase: function pointer is set on enum constant (danmar#7037)
1 parent 1e79d8b commit 61b75e6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/symboldatabase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5993,6 +5993,9 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
59935993

59945994
const Function* SymbolDatabase::findFunction(const Token* const tok) const
59955995
{
5996+
if (tok->tokType() == Token::Type::eEnumerator)
5997+
return nullptr;
5998+
59965999
// find the scope this function is in
59976000
const Scope *currScope = tok->scope();
59986001
while (currScope && currScope->isExecutable()) {

test/testsymboldatabase.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ class TestSymbolDatabase : public TestFixture {
521521
TEST_CASE(findFunction55); // #13004
522522
TEST_CASE(findFunction56);
523523
TEST_CASE(findFunction57);
524+
TEST_CASE(findFunction58); // #13310
524525
TEST_CASE(findFunctionRef1);
525526
TEST_CASE(findFunctionRef2); // #13328
526527
TEST_CASE(findFunctionContainer);
@@ -8376,6 +8377,19 @@ class TestSymbolDatabase : public TestFixture {
83768377
ASSERT_EQUALS(T->function()->tokenDef->linenr(), 6);
83778378
}
83788379

8380+
void findFunction58() { // #13310
8381+
GET_SYMBOL_DB("class C {\n"
8382+
" enum class abc : uint8_t {\n"
8383+
" a,b,c\n"
8384+
" };\n"
8385+
" void a();\n"
8386+
"};\n");
8387+
const Token *a1 = Token::findsimplematch(tokenizer.tokens(), "a ,");
8388+
ASSERT(a1 && !a1->function());
8389+
const Token *a2 = Token::findsimplematch(tokenizer.tokens(), "a (");
8390+
ASSERT(a2 && a2->function());
8391+
}
8392+
83798393
void findFunctionRef1() {
83808394
GET_SYMBOL_DB("struct X {\n"
83818395
" const std::vector<int> getInts() const & { return mInts; }\n"

0 commit comments

Comments
 (0)