Symbol database: Improved function lookup for foo.f(). Ticket #4494

This commit is contained in:
Robert Reif 2013-01-23 16:53:55 +01:00 committed by Daniel Marjamäki
parent 683c8adb74
commit cecd726b11
2 changed files with 24 additions and 0 deletions

View File

@ -2434,6 +2434,19 @@ const Function* SymbolDatabase::findFunctionByNameAndArgs(const Token *tok, cons
}
}
// check for member function
else if (tok->strAt(-1) == ".") {
if (Token::Match(tok->tokAt(-2), "%var% .")) {
const Token *tok1 = tok->tokAt(-2);
if (tok1->varId()) {
const Variable *var = getVariableFromVarId(tok1->varId());
if (var && var->type())
return findFunctionByNameAndArgsInScope(tok, var->type());
}
}
}
// check in enclosing scopes
else {
while (currScope) {

View File

@ -2714,6 +2714,17 @@ private:
"[test.cpp:13]: (error) Uninitialized variable: p\n"
"[test.cpp:15]: (error) Uninitialized variable: p\n"
"[test.cpp:17]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar2("class Fred {\n"
"public:\n"
" void f1(char *p) { *p = 0; }\n"
"};\n"
"Fred fred;\n"
"void f(void) {\n"
" char *p;\n"
" fred.f1(p);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: p\n", errout.str());
}
};