From ecafe7a12994fd1e7ad829c1930fb61e877719d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 28 Feb 2013 17:02:58 +0100 Subject: [PATCH] Fixed #4624 (Wrong error for instances of std::unique_lock (variable is never used)) --- lib/checkunusedvar.cpp | 3 ++- test/testunusedvar.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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)"