Symbol database: added simple mismatch check in Scope::findFunction when passing address to function that expects a reference
This commit is contained in:
parent
690c37633b
commit
ed9153ee80
|
@ -2506,6 +2506,17 @@ const Function* Scope::findFunction(const Token *tok) const
|
|||
const Token *arg = tok->tokAt(2);
|
||||
while (arg && arg->str() != ")") {
|
||||
/** @todo check argument type for match */
|
||||
|
||||
// mismatch parameter: passing parameter by address to function, argument is reference
|
||||
if (arg->str() == "&") {
|
||||
// check that function argument type is not mismatching
|
||||
const Variable *funcarg = func->getArgumentVar(args);
|
||||
if (funcarg && funcarg->isReference()) {
|
||||
args = ~0U;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
args++;
|
||||
arg = arg->nextArgument();
|
||||
}
|
||||
|
|
|
@ -212,6 +212,7 @@ private:
|
|||
TEST_CASE(garbage);
|
||||
|
||||
TEST_CASE(findFunction1);
|
||||
TEST_CASE(findFunction2); // mismatch: parameter passed by address => reference argument
|
||||
}
|
||||
|
||||
void array() const {
|
||||
|
@ -1857,6 +1858,20 @@ private:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void findFunction2() {
|
||||
// The function does not match the function call.
|
||||
GET_SYMBOL_DB("void func(const int x, const Fred &fred);\n"
|
||||
"void otherfunc() {\n"
|
||||
" float t;\n"
|
||||
" func(x, &t);\n"
|
||||
"}");
|
||||
const Token *callfunc = Token::findmatch(tokenizer.tokens(), "func ( x , & t ) ;");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS(true, db != nullptr); // not null
|
||||
ASSERT_EQUALS(true, callfunc != nullptr); // not null
|
||||
ASSERT_EQUALS(false, (callfunc && callfunc->function())); // callfunc->function() should be null
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSymbolDatabase)
|
||||
|
|
Loading…
Reference in New Issue