Fix false positive with ignoredReturnValue with std::move (#1809)

This commit is contained in:
Paul Fultz II 2019-04-26 05:22:31 -05:00 committed by Daniel Marjamäki
parent b1ca7c9a66
commit e856920488
2 changed files with 9 additions and 1 deletions

View File

@ -198,7 +198,7 @@ void CheckFunctions::checkIgnoredReturnValue()
for (const Scope *scope : symbolDatabase->functionScopes) { for (const Scope *scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
// skip c++11 initialization, ({...}) // skip c++11 initialization, ({...})
if (Token::Match(tok, "%var%|(|, {")) if (Token::Match(tok, "%var%|(|,|return {"))
tok = tok->linkAt(1); tok = tok->linkAt(1);
else if (Token::Match(tok, "[(<]") && tok->link()) else if (Token::Match(tok, "[(<]") && tok->link())
tok = tok->link(); tok = tok->link();

View File

@ -1175,6 +1175,14 @@ private:
" return std::get<0>(c);\n" " return std::get<0>(c);\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct A { int x; };\n"
"template <class... Ts>\n"
"A f(int x, Ts... xs) {\n"
" return {std::move(x), static_cast<int>(xs)...};\n"
"}\n"
"A g() { return f(1); }\n");
ASSERT_EQUALS("", errout.str());
} }
void memsetZeroBytes() { void memsetZeroBytes() {