Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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