Fixed #8933 (false negative: (style) Variable is assigned a value that is never used (std::string))
This commit is contained in:
parent
cf06acae08
commit
1cadd9398a
|
@ -1122,8 +1122,37 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
||||||
if ((!tok->isAssignmentOp() || !tok->astOperand1()) && !(Token::Match(tok, "%var% (") && tok->variable() && tok->variable()->nameToken() == tok))
|
if ((!tok->isAssignmentOp() || !tok->astOperand1()) && !(Token::Match(tok, "%var% (") && tok->variable() && tok->variable()->nameToken() == tok))
|
||||||
continue;
|
continue;
|
||||||
if (tok->isName()) {
|
if (tok->isName()) {
|
||||||
if (!tok->valueType() || !tok->valueType()->isIntegral())
|
if (mTokenizer->isCPP()) {
|
||||||
continue;
|
// do not check RAII/scope_lock objects
|
||||||
|
if (!tok->valueType())
|
||||||
|
continue;
|
||||||
|
bool check = false;
|
||||||
|
switch(tok->valueType()->type) {
|
||||||
|
case ValueType::Type::UNKNOWN_TYPE:
|
||||||
|
case ValueType::Type::NONSTD:
|
||||||
|
case ValueType::Type::RECORD:
|
||||||
|
check = tok->valueType()->typeScope && tok->valueType()->typeScope->getDestructor();
|
||||||
|
break;
|
||||||
|
case ValueType::Type::CONTAINER:
|
||||||
|
case ValueType::Type::ITERATOR:
|
||||||
|
case ValueType::Type::VOID:
|
||||||
|
case ValueType::Type::BOOL:
|
||||||
|
case ValueType::Type::CHAR:
|
||||||
|
case ValueType::Type::SHORT:
|
||||||
|
case ValueType::Type::WCHAR_T:
|
||||||
|
case ValueType::Type::INT:
|
||||||
|
case ValueType::Type::LONG:
|
||||||
|
case ValueType::Type::LONGLONG:
|
||||||
|
case ValueType::Type::UNKNOWN_INT:
|
||||||
|
case ValueType::Type::FLOAT:
|
||||||
|
case ValueType::Type::DOUBLE:
|
||||||
|
case ValueType::Type::LONGDOUBLE:
|
||||||
|
check = true;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
if (!check)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
if (tok->astParent() && tok->str() != "(") {
|
if (tok->astParent() && tok->str() != "(") {
|
||||||
|
|
|
@ -4124,18 +4124,13 @@ private:
|
||||||
functionVariableUsage("void f() {\n"
|
functionVariableUsage("void f() {\n"
|
||||||
" std::vector<int> x(100);\n"
|
" std::vector<int> x(100);\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n", "", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
|
||||||
|
|
||||||
functionVariableUsage("void f() {\n"
|
functionVariableUsage("void f() {\n"
|
||||||
" std::vector<MyClass> x;\n"
|
" std::vector<MyClass> x;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: x\n", errout.str());
|
||||||
|
|
||||||
functionVariableUsage("void f() {\n"
|
|
||||||
" std::vector<MyClass> x(100);\n" // Might have a side-effect
|
|
||||||
"}");
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
|
|
||||||
functionVariableUsage("void f() {\n"
|
functionVariableUsage("void f() {\n"
|
||||||
" std::lock_guard<MyClass> lock(mutex_);\n" // Has a side-effect #4385
|
" std::lock_guard<MyClass> lock(mutex_);\n" // Has a side-effect #4385
|
||||||
"}");
|
"}");
|
||||||
|
|
Loading…
Reference in New Issue