Fixed false positive ignoredReturnValue for variables initialized with constructor syntax (#6194)

This commit is contained in:
PKEuS 2014-09-29 10:14:58 +02:00
parent 798b845ce1
commit 1495a411eb
2 changed files with 7 additions and 1 deletions

View File

@ -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())

View File

@ -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());
}
};