Skip to content

Commit 466da1e

Browse files
Fix FP misusedScopedObject (cppcheck-opensource#5321)
1 parent 5371455 commit 466da1e

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ void CheckOther::checkMisusedScopedObject()
21392139
return;
21402140

21412141
auto getConstructorTok = [](const Token* tok, std::string& typeStr) -> const Token* {
2142-
if (!Token::Match(tok, "[;{}] %name%"))
2142+
if (!Token::Match(tok, "[;{}] %name%") || tok->next()->isKeyword())
21432143
return nullptr;
21442144
tok = tok->next();
21452145
typeStr.clear();

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5648,6 +5648,12 @@ class TestOther : public TestFixture {
56485648
"[test.cpp:6]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n"
56495649
"[test.cpp:9]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n",
56505650
errout.str());
5651+
5652+
check("struct S { int i; };\n"
5653+
"namespace {\n"
5654+
" S s() { return ::S{42}; }\n"
5655+
"}\n", "test.cpp");
5656+
ASSERT_EQUALS("", errout.str());
56515657
}
56525658

56535659
void testMisusedScopeObjectAssignment() { // #11371

0 commit comments

Comments
 (0)