diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index d67a02b14..7bc83e510 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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(), "=")) { diff --git a/lib/valueflow.h b/lib/valueflow.h index 646f1aa2a..688cb53e1 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -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; } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index b188d9e74..be8e62b1b 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() {