Fix FP misusedScopedObject (#5321)

This commit is contained in:
chrchr-github 2023-08-13 22:24:17 +02:00 committed by GitHub
parent 5371455606
commit 466da1e77a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -2139,7 +2139,7 @@ void CheckOther::checkMisusedScopedObject()
return; return;
auto getConstructorTok = [](const Token* tok, std::string& typeStr) -> const Token* { auto getConstructorTok = [](const Token* tok, std::string& typeStr) -> const Token* {
if (!Token::Match(tok, "[;{}] %name%")) if (!Token::Match(tok, "[;{}] %name%") || tok->next()->isKeyword())
return nullptr; return nullptr;
tok = tok->next(); tok = tok->next();
typeStr.clear(); typeStr.clear();

View File

@ -5648,6 +5648,12 @@ private:
"[test.cpp:6]: (style) Instance of 'std::scoped_lock' 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", "[test.cpp:9]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n",
errout.str()); errout.str());
check("struct S { int i; };\n"
"namespace {\n"
" S s() { return ::S{42}; }\n"
"}\n", "test.cpp");
ASSERT_EQUALS("", errout.str());
} }
void testMisusedScopeObjectAssignment() { // #11371 void testMisusedScopeObjectAssignment() { // #11371