Fix issue 9275: False positive: Non-local object uses local variable (#2084)
This commit is contained in:
parent
831f2009f5
commit
4f76588f98
|
@ -595,6 +595,8 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
|
||||||
} else if (tok->variable() && tok->variable()->declarationId() == tok->varId()) {
|
} else if (tok->variable() && tok->variable()->declarationId() == tok->varId()) {
|
||||||
var = tok->variable();
|
var = tok->variable();
|
||||||
}
|
}
|
||||||
|
if (!isLifetimeBorrowed(tok, mSettings))
|
||||||
|
continue;
|
||||||
if (var && !var->isLocal() && !var->isArgument() && !isVariableChanged(tok->next(), tok->scope()->bodyEnd, var->declarationId(), var->isGlobal(), mSettings, mTokenizer->isCPP())) {
|
if (var && !var->isLocal() && !var->isArgument() && !isVariableChanged(tok->next(), tok->scope()->bodyEnd, var->declarationId(), var->isGlobal(), mSettings, mTokenizer->isCPP())) {
|
||||||
errorDanglngLifetime(tok2, &val);
|
errorDanglngLifetime(tok2, &val);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1912,6 +1912,18 @@ private:
|
||||||
" return nullptr;\n"
|
" return nullptr;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #9275
|
||||||
|
check("struct S {\n"
|
||||||
|
" void f();\n"
|
||||||
|
" std::string m;\n"
|
||||||
|
"}\n"
|
||||||
|
"void S::f() {\n"
|
||||||
|
" char buf[1024];\n"
|
||||||
|
" const char* msg = buf;\n"
|
||||||
|
" m = msg;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void danglingLifetimeFunction() {
|
void danglingLifetimeFunction() {
|
||||||
|
|
Loading…
Reference in New Issue