checkLibraryCheckType: handle global scope operator / Fix FN unreadVariable (#5199)
This commit is contained in:
parent
977e1320d7
commit
e063656173
|
@ -1213,7 +1213,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
continue;
|
||||
tok = tok->next();
|
||||
}
|
||||
if (tok->astParent() && !tok->astParent()->isAssignmentOp() && tok->str() != "(") {
|
||||
if (!isInitialization && tok->astParent() && !tok->astParent()->isAssignmentOp() && tok->str() != "(") {
|
||||
const Token *parent = tok->astParent();
|
||||
while (Token::Match(parent, "%oror%|%comp%|!|&&"))
|
||||
parent = parent->astParent();
|
||||
|
@ -1268,7 +1268,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
op1Var->isClass() &&
|
||||
(!op1Var->valueType() || op1Var->valueType()->type == ValueType::Type::UNKNOWN_TYPE)) {
|
||||
// Check in the library if we should bailout or not..
|
||||
const std::string typeName = op1Var->getTypeName();
|
||||
std::string typeName = op1Var->getTypeName();
|
||||
if (typeName.compare(0, 2, "::") == 0)
|
||||
typeName.erase(typeName.begin(), typeName.begin() + 2);
|
||||
switch (mSettings->library.getTypeCheck("unusedvar", typeName)) {
|
||||
case Library::TypeCheck::def:
|
||||
bailoutTypeName = typeName;
|
||||
|
|
|
@ -6197,6 +6197,15 @@ private:
|
|||
" s[0] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("struct S {\n"
|
||||
" std::mutex m;\n"
|
||||
" void f();\n"
|
||||
"};\n"
|
||||
"void S::f() {\n"
|
||||
" const ::std::lock_guard g(m);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localVarClass() {
|
||||
|
@ -6478,6 +6487,11 @@ private:
|
|||
" std::list<std::list<int>>::value_type a{ 1, 2, 3, 4 };\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (information) --check-library: Provide <type-checks><unusedvar> configuration for std::list::value_type\n", errout.str());
|
||||
|
||||
functionVariableUsage("void f(int* p) {\n"
|
||||
" int* q{ p };\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'q' is assigned a value that is never used.\n", errout.str());
|
||||
}
|
||||
|
||||
void localvarRangeBasedFor() {
|
||||
|
|
Loading…
Reference in New Issue