Skip to content

Commit

Permalink
checkLibraryCheckType: handle global scope operator
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jun 26, 2023
1 parent 9dc38f8 commit b4e0cfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.find("::") == 0)
typeName.erase(typeName.begin(), typeName.begin() + 2);
switch (mSettings->library.getTypeCheck("unusedvar", typeName)) {
case Library::TypeCheck::def:
bailoutTypeName = typeName;
Expand Down
9 changes: 9 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6171,6 +6171,15 @@ class TestUnusedVar : public TestFixture {
functionVariableUsage("void f(std::span<int> s) {\n" // #11545
" 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());
}

Expand Down

0 comments on commit b4e0cfb

Please sign in to comment.