Fixed #7909 (Crash in CheckMemoryLeakInClass)
This commit is contained in:
parent
873513665b
commit
8e0f1ec788
|
@ -1510,8 +1510,12 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
|||
}
|
||||
|
||||
// skip over modifiers and other stuff
|
||||
while (Token::Match(tok1, "const|static|extern|template|virtual|struct|class|enum|%name%"))
|
||||
while (Token::Match(tok1, "const|static|extern|template|virtual|struct|class|enum|%name%")) {
|
||||
// friend type func(); is not a function
|
||||
if (isCPP() && tok1->str() == "friend" && tok2->str() == ";")
|
||||
return false;
|
||||
tok1 = tok1->previous();
|
||||
}
|
||||
|
||||
// should be at a sequence point if this is a function
|
||||
if (!Token::Match(tok1, ">|{|}|;|public:|protected:|private:") && tok1)
|
||||
|
|
|
@ -252,6 +252,7 @@ private:
|
|||
TEST_CASE(symboldatabase53); // #7124 (library podtype)
|
||||
TEST_CASE(symboldatabase54); // #7257
|
||||
TEST_CASE(symboldatabase55); // #7767 (return unknown macro)
|
||||
TEST_CASE(symboldatabase56); // #7909
|
||||
|
||||
TEST_CASE(enum1);
|
||||
TEST_CASE(enum2);
|
||||
|
@ -2667,6 +2668,48 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void symboldatabase56() { // #7909
|
||||
{
|
||||
GET_SYMBOL_DB("class Class {\n"
|
||||
" class NestedClass {\n"
|
||||
" public:\n"
|
||||
" virtual void f();\n"
|
||||
" };\n"
|
||||
" friend void NestedClass::f();\n"
|
||||
"}");
|
||||
|
||||
ASSERT(db != nullptr);
|
||||
if (db) {
|
||||
ASSERT_EQUALS(0U, db->functionScopes.size());
|
||||
ASSERT(db->scopeList.back().type == Scope::eClass && db->scopeList.back().className == "NestedClass");
|
||||
ASSERT(db->scopeList.back().functionList.size() == 1U && !db->scopeList.back().functionList.front().hasBody());
|
||||
}
|
||||
}
|
||||
{
|
||||
GET_SYMBOL_DB("class Class {\n"
|
||||
" friend void f1();\n"
|
||||
" friend void f2() { }\n"
|
||||
"}");
|
||||
|
||||
ASSERT(db != nullptr);
|
||||
if (db) {
|
||||
ASSERT_EQUALS(1U, db->functionScopes.size());
|
||||
ASSERT(db->scopeList.back().type == Scope::eFunction && db->scopeList.back().className == "f2");
|
||||
ASSERT(db->scopeList.back().function && db->scopeList.back().function->hasBody());
|
||||
}
|
||||
}
|
||||
{
|
||||
GET_SYMBOL_DB_C("friend f1();\n"
|
||||
"friend f2() { }\n");
|
||||
|
||||
ASSERT(db != nullptr);
|
||||
if (db) {
|
||||
ASSERT_EQUALS(2U, db->scopeList.size());
|
||||
ASSERT_EQUALS(2U, db->scopeList.begin()->functionList.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void enum1() {
|
||||
GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");
|
||||
|
||||
|
|
Loading…
Reference in New Issue