Fix FP with non-local variable referencing a non-local variable (#1864)

This commit is contained in:
Paul Fultz II 2019-06-02 03:21:26 -05:00 committed by Daniel Marjamäki
parent 6ae7be0f53
commit 8a1c0dd017
2 changed files with 10 additions and 1 deletions

View File

@ -630,7 +630,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
break;
} else if (tok->variable() && tok->variable()->declarationId() == tok->varId() &&
!tok->variable()->isLocal() && !tok->variable()->isArgument() &&
isInScope(val.tokvalue, tok->scope())) {
isInScope(val.tokvalue->variable()->nameToken(), tok->scope())) {
errorDanglngLifetime(tok, &val);
break;
}

View File

@ -1721,6 +1721,15 @@ private:
" std::map< S, B > m2;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("struct A {\n"
" std::vector<int*> v;\n"
" int x;\n"
" void f() {\n"
" v.push_back(&x);\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetime() {