Skip to content

Commit da724f2

Browse files
autoantwortclaude
andcommitted
Only reset reference at function declarator parentheses
`int& (r)` and `int& UNUSED(r)` lost their reference flag, which gave uninitvar false positives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0fb00fb commit da724f2

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,7 @@ void Variable::evaluate(const Settings& settings)
25952595
} else if (tok->str() == "&&") { // Before simplification, && isn't split up
25962596
setFlag(fIsRValueRef, true);
25972597
setFlag(fIsReference, true); // Set also fIsReference
2598-
} else if (tok->str() == "(") {
2598+
} else if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") (")) {
25992599
// a reference before the parentheses belongs to the return type of a function pointer: int& (*f)()
26002600
setFlag(fIsRValueRef, false);
26012601
setFlag(fIsReference, false);

‎test/testsymboldatabase.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,18 @@ class TestSymbolDatabase : public TestFixture {
16371637
ASSERT(p->valueType());
16381638
ASSERT(p->valueType()->reference == Reference::None);
16391639
}
1640+
{ // parentheses that are no function declarator
1641+
GET_SYMBOL_DB("void foo(int& (r)) {}\n");
1642+
const Variable* const p = db->functionScopes.front()->function->getArgumentVar(0);
1643+
ASSERT(p);
1644+
ASSERT(p->isReference());
1645+
}
1646+
{
1647+
GET_SYMBOL_DB("void foo(int& UNUSED(r)) {}\n");
1648+
const Variable* const p = db->functionScopes.front()->function->getArgumentVar(0);
1649+
ASSERT(p);
1650+
ASSERT(p->isReference());
1651+
}
16401652
{ // reference to function pointer
16411653
GET_SYMBOL_DB("void foo(int (*&f)()) {}\n");
16421654
const Variable* const p = db->getVariableFromVarId(1);

0 commit comments

Comments
 (0)