Skip to content

Commit e8355eb

Browse files
committed
Add test
1 parent 70537aa commit e8355eb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

test/testautovariables.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,6 +3955,24 @@ class TestAutoVariables : public TestFixture {
39553955
" return a;\n"
39563956
"}\n");
39573957
ASSERT_EQUALS("", errout_str());
3958+
3959+
check("struct A { int& x; };\n"
3960+
"A f() {\n"
3961+
" int x = 0;\n"
3962+
" A a{ .x{x} };\n"
3963+
" return a;\n"
3964+
"}\n");
3965+
ASSERT_EQUALS(
3966+
"[test.cpp:4:13] -> [test.cpp:3:9] -> [test.cpp:5:12]: (error) Returning object that points to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n",
3967+
errout_str());
3968+
3969+
check("struct A { int x; int& r};\n"
3970+
"A f(int& r) {\n"
3971+
" int x = 0;\n"
3972+
" A a{ .x{x}, .r{r} };\n"
3973+
" return a;\n"
3974+
"}\n");
3975+
ASSERT_EQUALS("", errout_str());
39583976
}
39593977

39603978
void danglingLifetimeInitList() {

0 commit comments

Comments
 (0)