Fix issue 9987: false positive: danglingTempReference with && variable and assignment (#2907)
This commit is contained in:
parent
c4b3d4cd77
commit
e8c1c792a5
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue