Skip to content

Commit 9adab8a

Browse files
committed
Skip
1 parent 6d9e448 commit 9adab8a

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/checkautovariables.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
612612
if (tokvalue->exprId() == tok->exprId() && !(tok->variable() && tok->variable()->isArray()) &&
613613
!astIsContainerView(tok->astParent()))
614614
continue;
615+
if (tokvalue->str() == "=" && Token::simpleMatch(tokvalue->astOperand1(), "."))
616+
tokvalue = tokvalue->astOperand2();
615617
if ((tokvalue->variable() && !isEscapedReference(tokvalue->variable()) &&
616618
isInScope(tokvalue->variable()->nameToken(), scope)) ||
617619
isDeadTemporary(tokvalue, nullptr, mSettings->library)) {

test/testautovariables.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,16 @@ class TestAutoVariables : public TestFixture {
39373937
ASSERT_EQUALS(
39383938
"[test.cpp:6:30] -> [test.cpp:6:30] -> [test.cpp:6:21] -> [test.cpp:5:21] -> [test.cpp:8:12]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n",
39393939
errout_str());
3940+
3941+
check("struct A { int& x; };\n" // #14247
3942+
"A f() {\n"
3943+
" int x = 0;\n"
3944+
" A a{.x = x};\n"
3945+
" return a;\n"
3946+
"}\n");
3947+
ASSERT_EQUALS(
3948+
"[test.cpp:4:12] -> [test.cpp:5:12]: (error) Returning object that will be invalid when returning. [returnDanglingLifetime]\n",
3949+
errout_str());
39403950
}
39413951

39423952
void danglingLifetimeInitList() {

0 commit comments

Comments
 (0)