Formatting

This commit is contained in:
Paul 2020-09-04 11:59:30 -05:00
parent bb37b07def
commit 264c0cae8b
3 changed files with 9 additions and 4 deletions

View File

@ -530,12 +530,14 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
} else if (tokvalue->variable() && isDeadScope(tokvalue->variable()->nameToken(), tok->scope())) {
errorInvalidLifetime(tok, &val);
break;
} else if (!tokvalue->variable() && isDeadTemporary(mTokenizer->isCPP(), tokvalue, tok, &mSettings->library)) {
} else if (!tokvalue->variable() &&
isDeadTemporary(mTokenizer->isCPP(), tokvalue, tok, &mSettings->library)) {
errorDanglingTemporaryLifetime(tok, &val);
break;
}
}
if (tokvalue->variable() && (isInScope(tokvalue->variable()->nameToken(), tok->scope()) || (val.isSubFunctionLifetimeValue() && tokvalue->variable()->isLocal()))) {
if (tokvalue->variable() && (isInScope(tokvalue->variable()->nameToken(), tok->scope()) ||
(val.isSubFunctionLifetimeValue() && tokvalue->variable()->isLocal()))) {
const Variable * var = nullptr;
const Token * tok2 = tok;
if (Token::simpleMatch(tok->astParent(), "=")) {

View File

@ -217,7 +217,8 @@ namespace ValueFlow {
return valueType == ValueType::LIFETIME && lifetimeScope == LifetimeScope::Argument;
}
bool isSubFunctionLifetimeValue() const {
bool isSubFunctionLifetimeValue() const
{
return valueType == ValueType::LIFETIME && lifetimeScope == LifetimeScope::SubFunction;
}

View File

@ -2167,7 +2167,9 @@ private:
" add(&i);\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:8] -> [test.cpp:4] -> [test.cpp:7] -> [test.cpp:4]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:8] -> [test.cpp:8] -> [test.cpp:4] -> [test.cpp:7] -> [test.cpp:4]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n",
errout.str());
}
void danglingLifetime() {