From cecd726b11e13e145d779dbec35e292bc95557e4 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 23 Jan 2013 16:53:55 +0100 Subject: [PATCH] Symbol database: Improved function lookup for foo.f(). Ticket #4494 --- lib/symboldatabase.cpp | 13 +++++++++++++ test/testuninitvar.cpp | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ffa2f19cd..20a424a63 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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) { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index bfff1b162..d65c54313 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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()); } };