Fix FP when using deferred locks (#3441)

This commit is contained in:
Paul Fultz II 2021-09-04 12:06:48 -05:00 committed by GitHub
parent 9eb5eadd35
commit 82b725e540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -2711,13 +2711,15 @@ static bool isMutex(const Variable* var)
static bool isLockGuard(const Variable* var)
{
const Token* tok = Token::typeDecl(var->nameToken()).first;
return Token::Match(tok, "std :: lock_guard|unique_lock|scoped_lock");
return Token::Match(tok, "std :: lock_guard|unique_lock|scoped_lock|shared_lock");
}
static bool isLocalMutex(const Variable* var, const Scope* scope)
{
if (!var)
return false;
if (isLockGuard(var))
return false;
return !var->isReference() && !var->isRValueReference() && !var->isStatic() && var->scope() == scope;
}

View File

@ -5366,6 +5366,22 @@ private:
check("void foo() { int f = 0; auto g(f); g = g; }");
ASSERT_EQUALS("", errout.str());
check("struct foobar {\n"
" int foo;\n"
" std::shared_mutex foo_mtx;\n"
" int bar;\n"
" std::shared_mutex bar_mtx;\n"
"};\n"
"void f() {\n"
" foobar xyz;\n"
" {\n"
" std::shared_lock shared_foo_lock(xyz.foo_mtx, std::defer_lock);\n"
" std::shared_lock shared_bar_lock(xyz.bar_mtx, std::defer_lock);\n"
" std::scoped_lock shared_multi_lock(shared_foo_lock, shared_bar_lock);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};