SymbolDatabase::isFunction: Fix wrong detection function

This commit is contained in:
Daniel Marjamäki 2018-04-27 10:24:02 +02:00
parent 9fade65dbb
commit d15b945c9e
3 changed files with 27 additions and 2 deletions

View File

@ -1358,6 +1358,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
const Token* tok1 = tok->previous();
const Token* tok2 = tok->next()->link()->next();
if (!_tokenizer->isFunctionHead(tok->next(), ";:{"))
return false;
// skip over destructor "~"
if (tok1->str() == "~")
tok1 = tok1->previous();

View File

@ -1109,6 +1109,7 @@ public:
class CPPCHECKLIB SymbolDatabase {
friend class TestSymbolDatabase;
public:
SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
~SymbolDatabase();

View File

@ -296,7 +296,8 @@ private:
TEST_CASE(isImplicitlyVirtual);
TEST_CASE(isPure);
TEST_CASE(isFunction); // UNKNOWN_MACRO(a,b) { .. }
TEST_CASE(isFunction1); // UNKNOWN_MACRO(a,b) { .. }
TEST_CASE(isFunction2);
TEST_CASE(findFunction1);
TEST_CASE(findFunction2); // mismatch: parameter passed by address => reference argument
@ -3745,7 +3746,8 @@ private:
ASSERT(!(it++)->isPure());
}
}
void isFunction() { // #5602 - UNKNOWN_MACRO(a,b) { .. }
void isFunction1() { // #5602 - UNKNOWN_MACRO(a,b) { .. }
GET_SYMBOL_DB("TEST(a,b) {\n"
" std::vector<int> messages;\n"
" foo(messages[2].size());\n"
@ -3758,6 +3760,25 @@ private:
var->typeStartToken()->str() == "std");
}
void isFunction2() {
GET_SYMBOL_DB("void set_cur_cpu_spec()\n"
"{\n"
" t = PTRRELOC(t);\n"
"}\n"
"\n"
"cpu_spec * __init setup_cpu_spec()\n"
"{\n"
" t = PTRRELOC(t);\n"
" *PTRRELOC(&x) = &y;\n"
"}");
ASSERT(db != nullptr);
ASSERT(db && !db->isFunction(Token::findsimplematch(tokenizer.tokens(), "PTRRELOC ( &"), &db->scopeList.back(), nullptr, nullptr, nullptr));
ASSERT(db->findScopeByName("set_cur_cpu_spec") != nullptr);
// TODO: ASSERT(db->findScopeByName("setup_cpu_spec") != nullptr);
ASSERT(db->findScopeByName("PTRRELOC") == nullptr);
}
void findFunction1() {
GET_SYMBOL_DB("int foo(int x);\n" /* 1 */
"void foo();\n" /* 2 */