Formatting
This commit is contained in:
parent
bb37b07def
commit
264c0cae8b
|
@ -530,12 +530,14 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
|
||||||
} else if (tokvalue->variable() && isDeadScope(tokvalue->variable()->nameToken(), tok->scope())) {
|
} else if (tokvalue->variable() && isDeadScope(tokvalue->variable()->nameToken(), tok->scope())) {
|
||||||
errorInvalidLifetime(tok, &val);
|
errorInvalidLifetime(tok, &val);
|
||||||
break;
|
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);
|
errorDanglingTemporaryLifetime(tok, &val);
|
||||||
break;
|
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 Variable * var = nullptr;
|
||||||
const Token * tok2 = tok;
|
const Token * tok2 = tok;
|
||||||
if (Token::simpleMatch(tok->astParent(), "=")) {
|
if (Token::simpleMatch(tok->astParent(), "=")) {
|
||||||
|
|
|
@ -217,7 +217,8 @@ namespace ValueFlow {
|
||||||
return valueType == ValueType::LIFETIME && lifetimeScope == LifetimeScope::Argument;
|
return valueType == ValueType::LIFETIME && lifetimeScope == LifetimeScope::Argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSubFunctionLifetimeValue() const {
|
bool isSubFunctionLifetimeValue() const
|
||||||
|
{
|
||||||
return valueType == ValueType::LIFETIME && lifetimeScope == LifetimeScope::SubFunction;
|
return valueType == ValueType::LIFETIME && lifetimeScope == LifetimeScope::SubFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2167,7 +2167,9 @@ private:
|
||||||
" add(&i);\n"
|
" add(&i);\n"
|
||||||
" }\n"
|
" }\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() {
|
void danglingLifetime() {
|
||||||
|
|
Loading…
Reference in New Issue