Fix FP when using deferred locks (#3441)
This commit is contained in:
parent
9eb5eadd35
commit
82b725e540
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue