| 7163 | |
| 7164 | |
| 7165 | void findFunction1() { |
| 7166 | GET_SYMBOL_DB("int foo(int x);\n" /* 1 */ |
| 7167 | "void foo();\n" /* 2 */ |
| 7168 | "void bar() {\n" /* 3 */ |
| 7169 | " foo();\n" /* 4 */ |
| 7170 | " foo(1);\n" /* 5 */ |
| 7171 | "}"); /* 6 */ |
| 7172 | ASSERT_EQUALS("", errout_str()); |
| 7173 | ASSERT(db); |
| 7174 | const Scope * bar = db->findScopeByName("bar"); |
| 7175 | ASSERT(bar != nullptr); |
| 7176 | constexpr unsigned int linenrs[2] = { 2, 1 }; |
| 7177 | unsigned int index = 0; |
| 7178 | for (const Token * tok = bar->bodyStart->next(); tok != bar->bodyEnd; tok = tok->next()) { |
| 7179 | if (Token::Match(tok, "%name% (") && !tok->varId() && Token::simpleMatch(tok->linkAt(1), ") ;")) { |
| 7180 | const Function * function = db->findFunction(tok); |
| 7181 | ASSERT(function != nullptr); |
| 7182 | if (function) { |
| 7183 | std::stringstream expected; |
| 7184 | expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << std::endl; |
| 7185 | std::stringstream actual; |
| 7186 | actual << "Function call on line " << tok->linenr() << " calls function on line " << function->tokenDef->linenr() << std::endl; |
| 7187 | ASSERT_EQUALS(expected.str(), actual.str()); |
| 7188 | } |
| 7189 | index++; |
| 7190 | } |
| 7191 | } |
| 7192 | } |
| 7193 | |
| 7194 | void findFunction2() { |
| 7195 | // The function does not match the function call. |
nothing calls this directly
no test coverage detected