diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f16dad861..5ba5b3621 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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; } diff --git a/test/teststl.cpp b/test/teststl.cpp index 52e9d2113..deb11f336 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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()); } };