Fix FP with invalidContainerRef (#2141)

This commit is contained in:
Paul Fultz II 2019-09-02 23:41:35 -05:00 committed by Daniel Marjamäki
parent 5c172bb55a
commit 88d194214f
2 changed files with 11 additions and 1 deletions

View File

@ -839,7 +839,7 @@ void CheckStl::invalidContainer()
bool addressOf = false; bool addressOf = false;
const Variable* var = getLifetimeVariable(info.tok, ep, &addressOf); const Variable* var = getLifetimeVariable(info.tok, ep, &addressOf);
// Check the reference is created before the change // Check the reference is created before the change
if (var && !addressOf) { if (var && var->declarationId() == tok->varId() && !addressOf) {
// An argument always reaches // An argument always reaches
if (var->isArgument() || (!var->isReference() && !var->isRValueReference() && if (var->isArgument() || (!var->isReference() && !var->isRValueReference() &&
!isVariableDecl(tok) && reaches(var->nameToken(), tok, library, &ep))) { !isVariableDecl(tok) && reaches(var->nameToken(), tok, library, &ep))) {

View File

@ -3976,6 +3976,16 @@ private:
"}\n", "}\n",
true); true);
ASSERT_EQUALS("", errout.str()); 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() { void findInsert() {