From b4e0cfb60a82520b5f7a2c5809925a53bde8418c Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 26 Jun 2023 15:49:08 +0200 Subject: [PATCH] checkLibraryCheckType: handle global scope operator --- lib/checkunusedvar.cpp | 4 +++- test/testunusedvar.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index ed4fd69a375..4cadd9c332d 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 51562221b56..aff99c745ba 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -6171,6 +6171,15 @@ class TestUnusedVar : public TestFixture { functionVariableUsage("void f(std::span 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()); }