You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testautovariables.cpp
+36Lines changed: 36 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3937,6 +3937,42 @@ class TestAutoVariables : public TestFixture {
3937
3937
ASSERT_EQUALS(
3938
3938
"[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",
3939
3939
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:14] -> [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",
3949
+
errout_str());
3950
+
3951
+
check("struct A { int x; int& r};\n"
3952
+
"A f(int& r) {\n"
3953
+
" int x = 0;\n"
3954
+
" A a{.x = x, .r = r};\n"
3955
+
" return a;\n"
3956
+
"}\n");
3957
+
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",
0 commit comments