Add cfg for std::scoped_lock, handle template arguments in checkMisusedScopedObject() (#4615)
This commit is contained in:
parent
7d3ce62ee9
commit
d5d7446433
|
@ -8672,6 +8672,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
||||||
<suppress>std::basic_ofstream</suppress>
|
<suppress>std::basic_ofstream</suppress>
|
||||||
<checkFiniteLifetime>std::insert_iterator</checkFiniteLifetime>
|
<checkFiniteLifetime>std::insert_iterator</checkFiniteLifetime>
|
||||||
<checkFiniteLifetime>std::lock_guard</checkFiniteLifetime>
|
<checkFiniteLifetime>std::lock_guard</checkFiniteLifetime>
|
||||||
|
<checkFiniteLifetime>std::scoped_lock</checkFiniteLifetime>
|
||||||
<checkFiniteLifetime>std::unique_lock</checkFiniteLifetime>
|
<checkFiniteLifetime>std::unique_lock</checkFiniteLifetime>
|
||||||
<checkFiniteLifetime>std::shared_lock</checkFiniteLifetime>
|
<checkFiniteLifetime>std::shared_lock</checkFiniteLifetime>
|
||||||
<check>std::pair</check>
|
<check>std::pair</check>
|
||||||
|
|
|
@ -2105,11 +2105,14 @@ void CheckOther::checkMisusedScopedObject()
|
||||||
if (ctorTok && (((ctorTok->type() || ctorTok->isStandardType() || (ctorTok->function() && ctorTok->function()->isConstructor())) // TODO: The rhs of || should be removed; It is a workaround for a symboldatabase bug
|
if (ctorTok && (((ctorTok->type() || ctorTok->isStandardType() || (ctorTok->function() && ctorTok->function()->isConstructor())) // TODO: The rhs of || should be removed; It is a workaround for a symboldatabase bug
|
||||||
&& (!ctorTok->function() || ctorTok->function()->isConstructor()) // // is not a function on this scope or is function in this scope and it's a ctor
|
&& (!ctorTok->function() || ctorTok->function()->isConstructor()) // // is not a function on this scope or is function in this scope and it's a ctor
|
||||||
&& ctorTok->str() != "void") || isLibraryConstructor(tok->next(), typeStr))) {
|
&& ctorTok->str() != "void") || isLibraryConstructor(tok->next(), typeStr))) {
|
||||||
if (const Token* arg = ctorTok->next()->astOperand2()) {
|
const Token* parTok = ctorTok->next();
|
||||||
|
if (Token::simpleMatch(parTok, "<") && parTok->link())
|
||||||
|
parTok = parTok->link()->next();
|
||||||
|
if (const Token* arg = parTok->astOperand2()) {
|
||||||
if (!isConstStatement(arg, mTokenizer->isCPP()))
|
if (!isConstStatement(arg, mTokenizer->isCPP()))
|
||||||
continue;
|
continue;
|
||||||
if (ctorTok->strAt(1) == "(") {
|
if (parTok->str() == "(") {
|
||||||
if (arg->varId()) // TODO: check if this is a declaration
|
if (arg->varId() && !(arg->variable() && arg->variable()->nameToken() != arg))
|
||||||
continue;
|
continue;
|
||||||
const Token* rml = nextAfterAstRightmostLeaf(arg);
|
const Token* rml = nextAfterAstRightmostLeaf(arg);
|
||||||
if (rml && rml->previous() && rml->previous()->varId())
|
if (rml && rml->previous() && rml->previous()->varId())
|
||||||
|
|
|
@ -5140,9 +5140,17 @@ private:
|
||||||
" void f() {\n"
|
" void f() {\n"
|
||||||
" std::lock_guard<std::mutex>(m);\n"
|
" std::lock_guard<std::mutex>(m);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
" void g() {\n"
|
||||||
|
" std::scoped_lock<std::mutex>(m);\n"
|
||||||
|
" }\n"
|
||||||
|
" void h() {\n"
|
||||||
|
" std::scoped_lock(m);\n"
|
||||||
|
" }\n"
|
||||||
" std::mutex m;\n"
|
" std::mutex m;\n"
|
||||||
"}\n", "test.cpp");
|
"}\n", "test.cpp");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Instance of 'std::lock_guard' object is destroyed immediately.\n",
|
ASSERT_EQUALS("[test.cpp:3]: (style) Instance of 'std::lock_guard' object is destroyed immediately.\n"
|
||||||
|
"[test.cpp:6]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n"
|
||||||
|
"[test.cpp:9]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue