Fix issue 9987: false positive: danglingTempReference with && variable and assignment (#2907)

This commit is contained in:
Paul Fultz II 2020-11-16 23:52:12 -06:00 committed by GitHub
parent c4b3d4cd77
commit e8c1c792a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -2849,7 +2849,7 @@ std::vector<LifetimeToken> getLifetimeTokens(const Token* tok, bool escape, Valu
const Token *vartok = var->declEndToken()->astOperand2();
const bool temporary = isTemporary(true, vartok, nullptr, true);
const bool nonlocal = var->isStatic() || var->isGlobal();
if (vartok == tok || (nonlocal && temporary) || (!escape && var->isConst() && temporary))
if (vartok == tok || (nonlocal && temporary) || (!escape && (var->isConst() || var->isRValueReference()) && temporary))
return {{tok, true, std::move(errorPath)}};
if (vartok)
return getLifetimeTokens(vartok, escape, std::move(errorPath), depth - 1);

View File

@ -1764,6 +1764,22 @@ private:
" return cr;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #9987
check("void g(std::vector<int>);\n"
"void f() {\n"
" std::vector<int>&& v = {};\n"
" g(std::move(v));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void g(std::vector<int>);\n"
"std::vector<int> h();\n"
"void f() {\n"
" std::vector<int>&& v = h();\n"
" g(std::move(v));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void testglobalnamespace() {