Skip to content

Commit 65cc994

Browse files
committed
Fix #15305 (SymbolDatabase: enum/struct tag name gets Token::function() when a function with the same name exists)
1 parent bcee906 commit 65cc994

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
12081208
inTemplateArg = tok->link();
12091209
if (inTemplateArg == tok)
12101210
inTemplateArg = nullptr;
1211-
if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{}(,)>;:]]")) && !isReservedName(tok)) {
1211+
if (tok->isName() && !tok->function() && tok->varId() == 0 && !Token::Match(tok->previous(), "class|struct|union|enum") && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{}(,)>;:]]")) && !isReservedName(tok)) {
12121212
if (tok->strAt(1) == ">" && !tok->linkAt(1))
12131213
continue;
12141214

‎test/testsymboldatabase.cpp‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ class TestSymbolDatabase : public TestFixture {
549549
TEST_CASE(findFunction64); // overloaded operator()
550550
TEST_CASE(findFunction65);
551551
TEST_CASE(findFunction66); // #15104 - object passed for pointer to its class
552+
TEST_CASE(findFunction67); // #15305 - tag name same as function name
552553
TEST_CASE(findFunctionRef1);
553554
TEST_CASE(findFunctionRef2); // #13328
554555
TEST_CASE(findFunctionContainer);
@@ -9243,6 +9244,38 @@ class TestSymbolDatabase : public TestFixture {
92439244
}
92449245
}
92459246

9247+
void findFunction67() { // #15305 - tag name same as function name
9248+
{
9249+
GET_SYMBOL_DB_C("enum E { A };\n"
9250+
"void E(void);\n"
9251+
"int f(int x) {\n"
9252+
" return (enum E)x;\n"
9253+
"}\n");
9254+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "E {");
9255+
ASSERT(tok && !tok->function());
9256+
tok = Token::findsimplematch(tokenizer.tokens(), "E )");
9257+
ASSERT(tok && !tok->function());
9258+
tok = Token::findsimplematch(tokenizer.tokens(), "E ( ) ;");
9259+
ASSERT(tok && tok->function());
9260+
}
9261+
{
9262+
GET_SYMBOL_DB_C("struct S { int a; };\n"
9263+
"void S(void);\n");
9264+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "S {");
9265+
ASSERT(tok && !tok->function());
9266+
tok = Token::findsimplematch(tokenizer.tokens(), "S ( ) ;");
9267+
ASSERT(tok && tok->function());
9268+
}
9269+
{
9270+
GET_SYMBOL_DB_C("union U { int a; float b; };\n"
9271+
"void U(void);\n");
9272+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "U {");
9273+
ASSERT(tok && !tok->function());
9274+
tok = Token::findsimplematch(tokenizer.tokens(), "U ( ) ;");
9275+
ASSERT(tok && tok->function());
9276+
}
9277+
}
9278+
92469279
void findFunctionRef1() {
92479280
GET_SYMBOL_DB("struct X {\n"
92489281
" const std::vector<int> getInts() const & { return mInts; }\n"

0 commit comments

Comments
 (0)