Skip to content

Commit e26e91d

Browse files
committed
fix
1 parent dbe4b2b commit e26e91d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,14 +1201,21 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
12011201
}
12021202
}
12031203

1204+
// Is tok the name in an elaborated type specifier, i.e. "struct S" or "struct N::S"?
1205+
auto isElaboratedTypeName = [](const Token* tok) {
1206+
while (Token::Match(tok->tokAt(-2), "%name% ::"))
1207+
tok = tok->tokAt(-2);
1208+
return Token::Match(tok, "class|struct|union|enum") || Token::Match(tok->previous(), "class|struct|union|enum");
1209+
};
1210+
12041211
// Set function call pointers
12051212
const Token* inTemplateArg = nullptr;
12061213
for (Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
12071214
if (inTemplateArg == nullptr && tok->link() && tok->str() == "<")
12081215
inTemplateArg = tok->link();
12091216
if (inTemplateArg == tok)
12101217
inTemplateArg = nullptr;
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)) {
1218+
if (tok->isName() && !tok->function() && tok->varId() == 0 && !isElaboratedTypeName(tok) && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{}(,)>;:]]")) && !isReservedName(tok)) {
12121219
if (tok->strAt(1) == ">" && !tok->linkAt(1))
12131220
continue;
12141221

‎test/testsymboldatabase.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9301,6 +9301,17 @@ class TestSymbolDatabase : public TestFixture {
93019301
tok = Token::findsimplematch(tokenizer.tokens(), "U ( ) ;");
93029302
ASSERT(tok && tok->function());
93039303
}
9304+
{
9305+
GET_SYMBOL_DB("namespace N { struct S { int a; }; void S(int); }\n"
9306+
"int f() {\n"
9307+
" return sizeof(struct N::S) + sizeof(struct ::N::S);\n"
9308+
"}\n");
9309+
ASSERT(db);
9310+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "N :: S ) +");
9311+
ASSERT(tok && !tok->tokAt(2)->function());
9312+
tok = Token::findsimplematch(tokenizer.tokens(), ":: N :: S ) ;");
9313+
ASSERT(tok && !tok->tokAt(3)->function());
9314+
}
93049315
}
93059316

93069317
void findFunctionRef1() {

0 commit comments

Comments
 (0)