Fix getOverriddenFunction(), add test (#5213)
This commit is contained in:
parent
b99931c59c
commit
db49687ae5
|
@ -4394,7 +4394,7 @@ const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType
|
||||||
bool match = true;
|
bool match = true;
|
||||||
|
|
||||||
// check for matching return parameters
|
// check for matching return parameters
|
||||||
while (!Token::Match(temp1, "virtual|{|}|;")) {
|
while (!Token::Match(temp1, "virtual|public:|private:|protected:|{|}|;")) {
|
||||||
if (temp1->str() != temp2->str() &&
|
if (temp1->str() != temp2->str() &&
|
||||||
!(temp1->str() == derivedFromType->name() &&
|
!(temp1->str() == derivedFromType->name() &&
|
||||||
temp2->str() == baseType->name())) {
|
temp2->str() == baseType->name())) {
|
||||||
|
|
|
@ -249,6 +249,7 @@ private:
|
||||||
TEST_CASE(functionArgs20);
|
TEST_CASE(functionArgs20);
|
||||||
|
|
||||||
TEST_CASE(functionImplicitlyVirtual);
|
TEST_CASE(functionImplicitlyVirtual);
|
||||||
|
TEST_CASE(functionGetOverridden);
|
||||||
|
|
||||||
TEST_CASE(functionIsInlineKeyword);
|
TEST_CASE(functionIsInlineKeyword);
|
||||||
|
|
||||||
|
@ -2730,6 +2731,24 @@ private:
|
||||||
ASSERT_EQUALS(true, function && function->isImplicitlyVirtual(false));
|
ASSERT_EQUALS(true, function && function->isImplicitlyVirtual(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void functionGetOverridden() {
|
||||||
|
GET_SYMBOL_DB("struct B { virtual void f(); };\n"
|
||||||
|
"struct D : B {\n"
|
||||||
|
"public:\n"
|
||||||
|
" void f() override;\n"
|
||||||
|
"};\n"
|
||||||
|
"struct D2 : D { void f() override {} };\n");
|
||||||
|
ASSERT(db != nullptr);
|
||||||
|
ASSERT_EQUALS(5, db->scopeList.size());
|
||||||
|
const Function *func = db->scopeList.back().function;
|
||||||
|
ASSERT(func && func->nestedIn);
|
||||||
|
ASSERT_EQUALS("D2", func->nestedIn->className);
|
||||||
|
bool foundAllBaseClasses{};
|
||||||
|
const Function* baseFunc = func->getOverriddenFunction(&foundAllBaseClasses);
|
||||||
|
ASSERT(baseFunc && baseFunc->nestedIn && foundAllBaseClasses);
|
||||||
|
ASSERT_EQUALS("D", baseFunc->nestedIn->className);
|
||||||
|
}
|
||||||
|
|
||||||
void functionIsInlineKeyword() {
|
void functionIsInlineKeyword() {
|
||||||
GET_SYMBOL_DB("inline void fs() {}");
|
GET_SYMBOL_DB("inline void fs() {}");
|
||||||
(void)db;
|
(void)db;
|
||||||
|
|
Loading…
Reference in New Issue