diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5636f55a4..17ce079d6 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3883,10 +3883,11 @@ void CheckOther::checkMisusedScopedObject() withinFunction = false; } - if (withinFunction - && Token::Match(tok, "[;{}] %var% (") + if (withinFunction + && Token::Match(tok, "[;{}] %var% (") && isIdentifierObjectType(tok) - && !Token::Match(tok->tokAt(2)->link(), ") .") + && !Token::Match(tok->tokAt(2)->link(), ") ( %var%") + && !Token::simpleMatch(tok->tokAt(2)->link(), ") .") ) { tok = tok->next(); diff --git a/test/testother.cpp b/test/testother.cpp index 3b5ff0f3d..4e52b0487 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3120,10 +3120,9 @@ private: "\n" "int main()\n" "{\n" - " int a[] = {1, 2, 3, 4, 5};\n" - " const size_t n = sizeof a / sizeof a[0];\n" - " std::for_each(a, a + n, IncrementFunctor());\n" - " return a[0];\n" + " int a = 1;\n" + " IncrementFunctor()(a);\n" + " return a;\n" "}\n" ); ASSERT_EQUALS("", errout.str());