Fixed #4624 (Wrong error for instances of std::unique_lock (variable is never used))

This commit is contained in:
Daniel Marjamäki 2013-02-28 17:02:58 +01:00
parent ed03e2c845
commit ecafe7a129
2 changed files with 8 additions and 1 deletions

View File

@ -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;

View File

@ -3537,6 +3537,12 @@ private:
" std::lock_guard<MyClass> lock(mutex_);\n" // Has a side-effect #4385
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void f() {\n"
" std::mutex m;\n"
" std::unique_lock<std::mutex> lock(m);\n" // #4624
"}");
ASSERT_EQUALS("", errout.str());
}
// ticket #3104 - false positive when variable is read with "if (NOT var)"