diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ef67d469b..ff5c7e007 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2754,7 +2754,7 @@ void CheckOther::checkReturnIgnoredReturnValue() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { - if (!Token::Match(tok, "%var% (")) + if (tok->varId() || !Token::Match(tok, "%var% (")) continue; if (!tok->next()->astParent() && _settings->library.useretval.find(tok->str()) != _settings->library.useretval.end()) diff --git a/test/testother.cpp b/test/testother.cpp index afeff0035..61da1fe93 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6279,6 +6279,12 @@ private: " bool b = strcmp(a, b);\n" "}", "test.cpp", false, false, false, true, &settings_std); ASSERT_EQUALS("", errout.str()); + + // #6194 + check("void foo() {\n" + " std::ofstream log(logfile.c_str(), std::ios::out);\n" + "}", "test.cpp", false, false, false, true, &settings_std); + ASSERT_EQUALS("", errout.str()); } };