Skip to content

Commit cdfe92b

Browse files
IOBYTEdanmar
authored andcommitted
Fixed #7657 (False positive: Function parameter 'c' should be passed by reference.)
1 parent 8983997 commit cdfe92b

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,10 +2781,12 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
27812781
return;
27822782
} while (tok->str() != "," && tok->str() != ")" && tok->str() != "=");
27832783

2784-
const Token *typeTok = startTok->tokAt(startTok->str() == "const" ? 1 : 0);
2785-
if (typeTok->str() == "struct" || typeTok->str() == "enum")
2784+
const Token *typeTok = startTok;
2785+
// skip over stuff to get to type
2786+
while (Token::Match(typeTok, "const|enum|struct|::"))
27862787
typeTok = typeTok->next();
2787-
if (Token::Match(typeTok, "%type% ::"))
2788+
// skip over qualification
2789+
while (Token::Match(typeTok, "%type% ::"))
27882790
typeTok = typeTok->tokAt(2);
27892791

27902792
// check for argument with no name or missing varid

test/testsymboldatabase.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class TestSymbolDatabase: public TestFixture {
186186
TEST_CASE(functionArgs6); // #7651
187187
TEST_CASE(functionArgs7); // #7652
188188
TEST_CASE(functionArgs8); // #7653
189+
TEST_CASE(functionArgs9); // #7657
189190

190191
TEST_CASE(namespaces1);
191192
TEST_CASE(namespaces2);
@@ -1732,6 +1733,28 @@ class TestSymbolDatabase: public TestFixture {
17321733
}
17331734
}
17341735

1736+
void functionArgs9() { // #7657
1737+
GET_SYMBOL_DB("struct A {\n"
1738+
" struct B {\n"
1739+
" enum C { };\n"
1740+
" };\n"
1741+
"};\n"
1742+
"void foo(A::B::C c) { }");
1743+
ASSERT_EQUALS(true, db != nullptr);
1744+
if (db) {
1745+
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo (");
1746+
ASSERT_EQUALS(true, f && f->function());
1747+
if (f && f->function()) {
1748+
const Function *func = f->function();
1749+
ASSERT_EQUALS(true, func->argumentList.size() == 1 && func->argumentList.front().type());
1750+
if (func->argumentList.size() == 1 && func->argumentList.front().type()) {
1751+
const Type * type = func->argumentList.front().type();
1752+
ASSERT_EQUALS(true, type->isEnumType());
1753+
}
1754+
}
1755+
}
1756+
}
1757+
17351758
void namespaces1() {
17361759
GET_SYMBOL_DB("namespace fred {\n"
17371760
" namespace barney {\n"

0 commit comments

Comments
 (0)