Fixed #4385: lock_guard RAII throws unreadVariable

This commit is contained in:
Frank Zingsheim 2013-01-07 20:28:43 +01:00
parent 049c995c99
commit 498d03458f
2 changed files with 10 additions and 1 deletions

View File

@ -684,7 +684,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
type = Variables::pointerPointer;
else if (i->isPointer())
type = Variables::pointer;
else if (_tokenizer->isC() || i->typeEndToken()->isStandardType() || isRecordTypeWithoutSideEffects(i->type()) || Token::simpleMatch(i->typeStartToken(), "std ::"))
else if (_tokenizer->isC() ||
i->typeEndToken()->isStandardType() ||
isRecordTypeWithoutSideEffects(i->type()) ||
(Token::simpleMatch(i->typeStartToken(), "std ::") &&
i->typeStartToken()->strAt(2) != "lock_guard"))
type = Variables::standard;
if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken()))
continue;

View File

@ -3512,6 +3512,11 @@ private:
" std::vector<MyClass> x(100);\n" // Might have a side-effect
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void f() {\n"
" std::lock_guard<MyClass> lock(mutex_);\n" // Has a side-effect #4385
"}");
ASSERT_EQUALS("", errout.str());
}
// ticket #3104 - false positive when variable is read with "if (NOT var)"