Skip to content

Commit dbe4b2b

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 dbe4b2b

2 files changed

Lines changed: 61 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: 60 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,65 @@ 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+
ASSERT(db);
9255+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "E {");
9256+
ASSERT(tok && !tok->function());
9257+
tok = Token::findsimplematch(tokenizer.tokens(), "E )");
9258+
ASSERT(tok && !tok->function());
9259+
tok = Token::findsimplematch(tokenizer.tokens(), "E ( ) ;");
9260+
ASSERT(tok && tok->function());
9261+
}
9262+
{
9263+
GET_SYMBOL_DB_C("struct S { int a; int b; };\n"
9264+
"void S(void);\n"
9265+
"int f(void *p) {\n"
9266+
" return ((struct S *)p)->a + sizeof(struct S);\n"
9267+
"}\n"
9268+
"int g(void) {\n"
9269+
" return (struct S){1, 2}.a;\n"
9270+
"}\n");
9271+
ASSERT(db);
9272+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "S {");
9273+
ASSERT(tok && !tok->function());
9274+
tok = Token::findsimplematch(tokenizer.tokens(), "S *");
9275+
ASSERT(tok && !tok->function());
9276+
tok = Token::findsimplematch(tokenizer.tokens(), "S )");
9277+
ASSERT(tok && !tok->function());
9278+
tok = Token::findsimplematch(tokenizer.tokens(), "S ) {");
9279+
ASSERT(tok && !tok->function());
9280+
tok = Token::findsimplematch(tokenizer.tokens(), "S ( ) ;");
9281+
ASSERT(tok && tok->function());
9282+
}
9283+
{
9284+
GET_SYMBOL_DB_C("union U { int a; float b; };\n"
9285+
"void U(void);\n"
9286+
"int f(void *p) {\n"
9287+
" return ((union U *)p)->a + sizeof(union U);\n"
9288+
"}\n"
9289+
"int g(void) {\n"
9290+
" return (union U){3}.a;\n"
9291+
"}\n");
9292+
ASSERT(db);
9293+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "U {");
9294+
ASSERT(tok && !tok->function());
9295+
tok = Token::findsimplematch(tokenizer.tokens(), "U *");
9296+
ASSERT(tok && !tok->function());
9297+
tok = Token::findsimplematch(tokenizer.tokens(), "U )");
9298+
ASSERT(tok && !tok->function());
9299+
tok = Token::findsimplematch(tokenizer.tokens(), "U ) {");
9300+
ASSERT(tok && !tok->function());
9301+
tok = Token::findsimplematch(tokenizer.tokens(), "U ( ) ;");
9302+
ASSERT(tok && tok->function());
9303+
}
9304+
}
9305+
92469306
void findFunctionRef1() {
92479307
GET_SYMBOL_DB("struct X {\n"
92489308
" const std::vector<int> getInts() const & { return mInts; }\n"

0 commit comments

Comments
 (0)