#6301 Unused shared lock variable. Add exception for std::shared_lock() to CheckUnusedVar::checkFunctionVariableUsage_iterateScopes()

This commit is contained in:
Alexander Mai 2014-12-07 15:32:09 +01:00
parent d11eb4931a
commit ec2c4aa2e3
2 changed files with 7 additions and 2 deletions

View File

@ -694,7 +694,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
i->typeEndToken()->isStandardType() || i->typeEndToken()->isStandardType() ||
isRecordTypeWithoutSideEffects(i->type()) || isRecordTypeWithoutSideEffects(i->type()) ||
(i->isStlType() && (i->isStlType() &&
!Token::Match(i->typeStartToken()->tokAt(2), "lock_guard|unique_lock|shared_ptr|unique_ptr|auto_ptr"))) !Token::Match(i->typeStartToken()->tokAt(2), "lock_guard|unique_lock|shared_ptr|unique_ptr|auto_ptr|shared_lock")))
type = Variables::standard; type = Variables::standard;
if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken())) if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken()))
continue; continue;

View File

@ -1870,7 +1870,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void localvar46() { // #5491/#5494 void localvar46() { // #5491/#5494/#6301
functionVariableUsage("int func() {\n" functionVariableUsage("int func() {\n"
" int i = 0;\n" " int i = 0;\n"
" int j{i};\n" " int j{i};\n"
@ -1884,6 +1884,11 @@ private:
" return 0;\n" " return 0;\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
functionVariableUsage("int func() {\n"
" std::shared_lock<std::shared_timed_mutex> lock( m );\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void localvaralias1() { void localvaralias1() {