From 1495a411eb1a926664ea0e585da812fc307731c8 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 29 Sep 2014 10:14:58 +0200 Subject: [PATCH] Fixed false positive ignoredReturnValue for variables initialized with constructor syntax (#6194) --- lib/checkother.cpp | 2 +- test/testother.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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()); } };