Fix FP with invalidContainerRef (#2141)
This commit is contained in:
parent
5c172bb55a
commit
88d194214f
|
@ -839,7 +839,7 @@ void CheckStl::invalidContainer()
|
|||
bool addressOf = false;
|
||||
const Variable* var = getLifetimeVariable(info.tok, ep, &addressOf);
|
||||
// Check the reference is created before the change
|
||||
if (var && !addressOf) {
|
||||
if (var && var->declarationId() == tok->varId() && !addressOf) {
|
||||
// An argument always reaches
|
||||
if (var->isArgument() || (!var->isReference() && !var->isRValueReference() &&
|
||||
!isVariableDecl(tok) && reaches(var->nameToken(), tok, library, &ep))) {
|
||||
|
|
|
@ -3976,6 +3976,16 @@ private:
|
|||
"}\n",
|
||||
true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("std::vector<std::string> g();\n"
|
||||
"void f() {\n"
|
||||
" std::vector<std::string> x = g();\n"
|
||||
" const std::string& y = x[1];\n"
|
||||
" std::string z;\n"
|
||||
" z += \"\";\n"
|
||||
" z += y;\n"
|
||||
"}\n",true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void findInsert() {
|
||||
|
|
Loading…
Reference in New Issue