Fixed #1966 (False positive: Unused private function (virtual function in base class))
This commit is contained in:
parent
df87ce9e04
commit
0597c50a47
|
@ -1075,7 +1075,7 @@ void CheckClass::privateFunctions()
|
||||||
if (!_settings->_checkCodingStyle)
|
if (!_settings->_checkCodingStyle)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const char pattern_class[] = "class|struct %var% {|:";
|
const char pattern_class[] = "class|struct %var% {";
|
||||||
|
|
||||||
// Locate some class
|
// Locate some class
|
||||||
for (const Token *tok1 = Token::findmatch(_tokenizer->tokens(), pattern_class);
|
for (const Token *tok1 = Token::findmatch(_tokenizer->tokens(), pattern_class);
|
||||||
|
|
|
@ -50,6 +50,8 @@ private:
|
||||||
TEST_CASE(classInClass);
|
TEST_CASE(classInClass);
|
||||||
TEST_CASE(sameFunctionNames);
|
TEST_CASE(sameFunctionNames);
|
||||||
TEST_CASE(incompleteImplementation);
|
TEST_CASE(incompleteImplementation);
|
||||||
|
|
||||||
|
TEST_CASE(derivedClass); // skip warning for derived classes. It might be a virtual function.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -359,6 +361,19 @@ private:
|
||||||
"void A::b() { }\n");
|
"void A::b() { }\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void derivedClass()
|
||||||
|
{
|
||||||
|
// skip warning in derived classes in case the function is virtual
|
||||||
|
check("class derived : public base\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" derived() : base() { }\n"
|
||||||
|
"private:\n"
|
||||||
|
" void f();\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestUnusedPrivateFunction)
|
REGISTER_TEST(TestUnusedPrivateFunction)
|
||||||
|
|
Loading…
Reference in New Issue