diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 1507e770b..ed0e8619c 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -691,8 +691,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const i->typeEndToken()->isStandardType() || isRecordTypeWithoutSideEffects(i->type()) || (i->isStlType() && - i->typeStartToken()->strAt(2) != "lock_guard" && - i->typeStartToken()->strAt(2) != "unique_lock")) + !Token::Match(i->typeStartToken()->tokAt(2), "lock_guard|unique_lock|shared_ptr|unique_ptr|auto_ptr"))) type = Variables::standard; if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken())) continue; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 2fc67d0f8..0494f4e63 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -3685,6 +3685,11 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + functionVariableUsage("void f() {\n" + " pLocker = std::shared_ptr(new jfxLocker(m_lock, true));\n" // Could have side-effects (#4355) + "}"); + ASSERT_EQUALS("", errout.str()); + functionVariableUsage("void f() {\n" " std::mutex m;\n" " std::unique_lock lock(m);\n" // #4624