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;
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;
tok = tok->next();
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:9]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n",
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