diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 542710d0b..5636f55a4 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3883,7 +3883,11 @@ void CheckOther::checkMisusedScopedObject() withinFunction = false; } - if (withinFunction && Token::Match(tok, "[;{}] %var% (") && isIdentifierObjectType(tok)) + if (withinFunction + && Token::Match(tok, "[;{}] %var% (") + && isIdentifierObjectType(tok) + && !Token::Match(tok->tokAt(2)->link(), ") .") + ) { tok = tok->next(); misusedScopeObjectError(tok, tok->str()); diff --git a/test/testother.cpp b/test/testother.cpp index 62c463199..3b5ff0f3d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -113,6 +113,7 @@ private: TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration); TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor); TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassMethod); + TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject); } void check(const char code[]) @@ -3138,6 +3139,20 @@ private: ); ASSERT_EQUALS("", errout.str()); } + + void testMisusedScopeObjectDoesNotPickUsedObject() + { + check("struct Foo {\n" + " void bar() {\n" + " }\n" + "};\n" + "\n" + "void fn() {\n" + " Foo().bar();\n" + "}\n" + ); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestOther)