Repository navigation
Fix #15305 (SymbolDatabase: enum/struct tag name gets Token::function() when a function with the same name exists) - #9111
Conversation
…() when a function with the same name exists)
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The fix works for unqualified tag names. I found no regressions: in C, enum E, struct S and union U no longer get Token::function(), and the bogus !0 (function address) values on them are gone. One case is still not handled: a qualified elaborated name like struct N::S still links S to the function N::S, because the new check only looks at the token directly before the name.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | Qualified tag names (struct N::S) still get Token::function() |
AI review | lib/symboldatabase.cpp:1211 |
🆕 New (false negative) |
@danmar, please fix, resolve or reply to the open and new comments: #1.
For #1 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.
Testing
- Built
cppcheckandtestrunnerin pr/ andcppcheckin base/. ./testrunner TestSymbolDatabase: 432 tests, 0 failed. The full./testrunner: 5436 tests, 0 failed.- Compared
--debugoutput of base and PR on scratch C and C++ files that useenum E,struct Sandenum class Ein casts,sizeofand declarations next to functions of the same name:- In C, base gave
S always !0/E always !0(function address values) and wrong values on the expression. PR gives. always 4etc. - In C++, the spurious
E always !0on(enum class E)xis gone.
- In C, base gave
- Ran
samples/andtest/cfg/*.cwith--enable=all --inconclusive: output is the same in base and PR. - One case is still wrong:
namespace N { struct S { int a; }; void S(int); }
int f(void *p) {
return ((struct N::S*)p)->a + sizeof(struct N::S);
}pr/cppcheck --debug c.cpp still prints S always !0 for the S in sizeof(struct N::S), so the token is still linked to the function. Base prints the same, so this is not a regression.
Automated review of dbe4b2b by Claude. The pull request was built and tested locally.
| if (inTemplateArg == tok) | ||
| inTemplateArg = nullptr; | ||
| if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{}(,)>;:]]")) && !isReservedName(tok)) { | ||
| 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)) { |
There was a problem hiding this comment.
AI review
The check only looks at tok->previous(), so a qualified elaborated type specifier is not covered. With namespace N { struct S { int a; }; void S(int); } and sizeof(struct N::S), the S token still gets the function, and --debug shows S always !0. You could walk back over %name% :: chains before matching class|struct|union|enum.
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. The qualified tag case from the earlier review is fixed: isElaboratedTypeName now walks back over %name% :: chains, so struct N::S and struct ::N::S are covered, and the PR adds a test for both. A function name used as a function pointer next to a struct with the same name (void (*fp)(int) = T;) is still linked to the function.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | Qualified elaborated tag names (struct N::S) still get Token::function() |
AI review | lib/symboldatabase.cpp:1211 |
✅ Fixed |
Testing
- Built
cppcheckandtestrunnerin pr/ with no warnings or errors. ./testrunner TestSymbolDatabase: 432 tests, 0 failed. The full./testrunner -q: 0 failed.- Ran
pr/cppcheck --debugon a scratch file withstruct N::S,struct ::N::Sandenum class N::Sin casts andsizeof, all next to a functionN::S. None of theStokens got the bogusalways !0value any more; thesizeofresults came out as numbers (( always 4). - In the same file,
struct T {...}; void T(int); void (*fp)(int) = T;still givesT always !0, so a function name used as a function pointer is still linked to the function.
Automated review of e26e91d by Claude. The pull request was built and tested locally.
No description provided.