Fix issue 8883: False positive: returnDanglingLifetime with local struct or class (#1585)

This commit is contained in:
Paul Fultz II 2019-01-11 02:51:02 -06:00 committed by Daniel Marjamäki
parent 5fa956a597
commit 921f6e4313
2 changed files with 20 additions and 0 deletions

View File

@ -655,6 +655,18 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
checkVarLifetimeScope(lambdaEndToken->link(), lambdaEndToken);
tok = lambdaEndToken;
}
if (tok->str() == "{" && tok->scope()) {
// Check functions in local classes
if (tok->scope()->type == Scope::eClass ||
tok->scope()->type == Scope::eStruct ||
tok->scope()->type == Scope::eUnion) {
for(const Function& f:tok->scope()->functionList) {
if (f.functionScope)
checkVarLifetimeScope(f.functionScope->bodyStart, f.functionScope->bodyEnd);
}
tok = tok->link();
}
}
}
}

View File

@ -1643,6 +1643,14 @@ private:
" return d;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" struct a {\n"
" std::vector<int> v;\n"
" auto g() { return v.end(); }\n"
" };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeFunction() {