Skip to content

Commit ecafe7a

Browse files
committed
Fixed danmar#4624 (Wrong error for instances of std::unique_lock (variable is never used))
1 parent ed03e2c commit ecafe7a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/checkunusedvar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
692692
i->typeEndToken()->isStandardType() ||
693693
isRecordTypeWithoutSideEffects(i->type()) ||
694694
(Token::simpleMatch(i->typeStartToken(), "std ::") &&
695-
i->typeStartToken()->strAt(2) != "lock_guard"))
695+
i->typeStartToken()->strAt(2) != "lock_guard" &&
696+
i->typeStartToken()->strAt(2) != "unique_lock"))
696697
type = Variables::standard;
697698
if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken()))
698699
continue;

test/testunusedvar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,6 +3537,12 @@ class TestUnusedVar : public TestFixture {
35373537
" std::lock_guard<MyClass> lock(mutex_);\n" // Has a side-effect #4385
35383538
"}");
35393539
ASSERT_EQUALS("", errout.str());
3540+
3541+
functionVariableUsage("void f() {\n"
3542+
" std::mutex m;\n"
3543+
" std::unique_lock<std::mutex> lock(m);\n" // #4624
3544+
"}");
3545+
ASSERT_EQUALS("", errout.str());
35403546
}
35413547

35423548
// ticket #3104 - false positive when variable is read with "if (NOT var)"

0 commit comments

Comments
 (0)