Fixed #7657 (False positive: Function parameter 'c' should be passed by reference.)

This commit is contained in:
Robert Reif 2016-08-06 10:27:00 +02:00 committed by Daniel Marjamäki
parent 8983997a88
commit cdfe92b753
2 changed files with 28 additions and 3 deletions

View File

@ -2781,10 +2781,12 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
return; return;
} while (tok->str() != "," && tok->str() != ")" && tok->str() != "="); } while (tok->str() != "," && tok->str() != ")" && tok->str() != "=");
const Token *typeTok = startTok->tokAt(startTok->str() == "const" ? 1 : 0); const Token *typeTok = startTok;
if (typeTok->str() == "struct" || typeTok->str() == "enum") // skip over stuff to get to type
while (Token::Match(typeTok, "const|enum|struct|::"))
typeTok = typeTok->next(); typeTok = typeTok->next();
if (Token::Match(typeTok, "%type% ::")) // skip over qualification
while (Token::Match(typeTok, "%type% ::"))
typeTok = typeTok->tokAt(2); typeTok = typeTok->tokAt(2);
// check for argument with no name or missing varid // check for argument with no name or missing varid

View File

@ -186,6 +186,7 @@ private:
TEST_CASE(functionArgs6); // #7651 TEST_CASE(functionArgs6); // #7651
TEST_CASE(functionArgs7); // #7652 TEST_CASE(functionArgs7); // #7652
TEST_CASE(functionArgs8); // #7653 TEST_CASE(functionArgs8); // #7653
TEST_CASE(functionArgs9); // #7657
TEST_CASE(namespaces1); TEST_CASE(namespaces1);
TEST_CASE(namespaces2); TEST_CASE(namespaces2);
@ -1732,6 +1733,28 @@ private:
} }
} }
void functionArgs9() { // #7657
GET_SYMBOL_DB("struct A {\n"
" struct B {\n"
" enum C { };\n"
" };\n"
"};\n"
"void foo(A::B::C c) { }");
ASSERT_EQUALS(true, db != nullptr);
if (db) {
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo (");
ASSERT_EQUALS(true, f && f->function());
if (f && f->function()) {
const Function *func = f->function();
ASSERT_EQUALS(true, func->argumentList.size() == 1 && func->argumentList.front().type());
if (func->argumentList.size() == 1 && func->argumentList.front().type()) {
const Type * type = func->argumentList.front().type();
ASSERT_EQUALS(true, type->isEnumType());
}
}
}
}
void namespaces1() { void namespaces1() {
GET_SYMBOL_DB("namespace fred {\n" GET_SYMBOL_DB("namespace fred {\n"
" namespace barney {\n" " namespace barney {\n"