Fixed false positive: The function 'operatorstd::string' is never used. (#7853)
This commit is contained in:
parent
d120fdc9a7
commit
120fe2e4d6
|
@ -54,7 +54,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Don't warn about functions that are marked by __attribute__((constructor)) or __attribute__((destructor))
|
// Don't warn about functions that are marked by __attribute__((constructor)) or __attribute__((destructor))
|
||||||
if (func->isAttributeConstructor() || func->isAttributeDestructor() || func->type != Function::eFunction)
|
if (func->isAttributeConstructor() || func->isAttributeDestructor() || func->type != Function::eFunction || func->isOperator())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Don't care about templates
|
// Don't care about templates
|
||||||
|
@ -234,14 +234,11 @@ void CheckUnusedFunctions::check(ErrorLogger * const errorLogger, const Settings
|
||||||
continue;
|
continue;
|
||||||
if (it->first == "main" ||
|
if (it->first == "main" ||
|
||||||
(settings.isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) ||
|
(settings.isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) ||
|
||||||
it->first == "if" ||
|
it->first == "if")
|
||||||
(it->first.compare(0, 8, "operator") == 0 && it->first.size() > 8 && !std::isalnum(it->first[8])))
|
|
||||||
continue;
|
continue;
|
||||||
if (! func.usedSameFile) {
|
if (!func.usedSameFile) {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
if (func.filename == "+")
|
if (func.filename != "+")
|
||||||
filename = "";
|
|
||||||
else
|
|
||||||
filename = func.filename;
|
filename = func.filename;
|
||||||
unusedFunctionError(errorLogger, filename, func.lineNumber, it->first);
|
unusedFunctionError(errorLogger, filename, func.lineNumber, it->first);
|
||||||
} else if (! func.usedOtherFile) {
|
} else if (! func.usedOtherFile) {
|
||||||
|
@ -355,7 +352,7 @@ void CheckUnusedFunctions::analyseWholeProgram(ErrorLogger * const errorLogger,
|
||||||
const std::string &functionName = decl->first;
|
const std::string &functionName = decl->first;
|
||||||
|
|
||||||
if (functionName == "main" || functionName == "WinMain" || functionName == "_tmain" ||
|
if (functionName == "main" || functionName == "WinMain" || functionName == "_tmain" ||
|
||||||
functionName == "if" || functionName.compare(0, 8, "operator") == 0)
|
functionName == "if")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (calls.find(functionName) == calls.end()) {
|
if (calls.find(functionName) == calls.end()) {
|
||||||
|
|
|
@ -247,6 +247,9 @@ private:
|
||||||
void operator1() {
|
void operator1() {
|
||||||
check("struct Foo { void operator()(int a) {} };");
|
check("struct Foo { void operator()(int a) {} };");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("struct Foo { operator std::string(int a) {} };");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void returnRef() {
|
void returnRef() {
|
||||||
|
|
Loading…
Reference in New Issue