diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 53c90d95f..9287b5102 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -692,7 +692,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const i->typeEndToken()->isStandardType() || isRecordTypeWithoutSideEffects(i->type()) || (Token::simpleMatch(i->typeStartToken(), "std ::") && - i->typeStartToken()->strAt(2) != "lock_guard")) + i->typeStartToken()->strAt(2) != "lock_guard" && + i->typeStartToken()->strAt(2) != "unique_lock")) type = Variables::standard; if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken())) continue; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 24f83577c..d44d81aac 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -3537,6 +3537,12 @@ private: " std::lock_guard lock(mutex_);\n" // Has a side-effect #4385 "}"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("void f() {\n" + " std::mutex m;\n" + " std::unique_lock lock(m);\n" // #4624 + "}"); + ASSERT_EQUALS("", errout.str()); } // ticket #3104 - false positive when variable is read with "if (NOT var)"