Fix ticket #2233 (unused private static function)
This commit is contained in:
parent
d76657fec8
commit
b0574cd02e
|
@ -619,10 +619,12 @@ void CheckClass::privateFunctions()
|
|||
// eg. sigc::mem_fun(this, &className::classFunction)
|
||||
const std::string _pattern2("& " + classname + " :: " + FuncList.front()->str());
|
||||
const std::string methodAsArgument("(|, " + classname + " :: " + FuncList.front()->str() + " ,|)");
|
||||
const std::string methodAssigned("%var% = &| " + classname + " :: " + FuncList.front()->str());
|
||||
|
||||
if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()) &&
|
||||
!Token::findmatch(_tokenizer->tokens(), _pattern2.c_str()) &&
|
||||
!Token::findmatch(_tokenizer->tokens(), methodAsArgument.c_str())
|
||||
) {
|
||||
!Token::findmatch(_tokenizer->tokens(), methodAsArgument.c_str()) &&
|
||||
!Token::findmatch(_tokenizer->tokens(), methodAssigned.c_str())) {
|
||||
unusedPrivateFunctionError(FuncList.front(), classname, FuncList.front()->str());
|
||||
}
|
||||
FuncList.pop_front();
|
||||
|
|
|
@ -207,6 +207,7 @@ private:
|
|||
TEST_CASE(constUnion); // ticket #2111 - fp when there are union
|
||||
|
||||
TEST_CASE(initializerList);
|
||||
TEST_CASE(unusedPrivate); // ticket #2233
|
||||
}
|
||||
|
||||
// Check the operator Equal
|
||||
|
@ -6386,6 +6387,35 @@ private:
|
|||
"[test.cpp:4] -> [test.cpp:2]: (style) Member variable 'Fred::a' is in the wrong order in the initializer list.\n", errout.str());
|
||||
}
|
||||
|
||||
void check(const char code[]) {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
Settings settings;
|
||||
settings.addEnabled("style");
|
||||
settings.inconclusive = true;
|
||||
|
||||
// Tokenize..
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
// Check..
|
||||
CheckClass checkClass(&tokenizer, &settings, this);
|
||||
checkClass.runSimplifiedChecks(&tokenizer, &settings, this);
|
||||
}
|
||||
|
||||
void unusedPrivate() {
|
||||
check("class A {\n"
|
||||
"public:\n"
|
||||
" A() { f = A::func; }\n"
|
||||
" void (*f)();\n"
|
||||
"private:\n"
|
||||
" static void func() { }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestClass)
|
||||
|
|
Loading…
Reference in New Issue