Skip to content

Commit

Permalink
Fix FP misusedScopedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 13, 2023
1 parent 5c6962c commit 3400f68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5648,6 +5648,12 @@ class TestOther : public TestFixture {
"[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
Expand Down

0 comments on commit 3400f68

Please sign in to comment.