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
+26-2Lines changed: 26 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -148,7 +148,7 @@ class TestAutoVariables : public TestFixture {
148
148
TEST_CASE(danglingLifetime);
149
149
TEST_CASE(danglingLifetimeFunction);
150
150
TEST_CASE(danglingLifetimeUserConstructor);
151
-
TEST_CASE(danglingLifetimeAggegrateConstructor);
151
+
TEST_CASE(danglingLifetimeAggregateConstructor);
152
152
TEST_CASE(danglingLifetimeInitList);
153
153
TEST_CASE(danglingLifetimeImplicitConversion);
154
154
TEST_CASE(danglingTemporaryLifetime);
@@ -3796,7 +3796,7 @@ class TestAutoVariables : public TestFixture {
3796
3796
ASSERT_EQUALS("", errout_str());
3797
3797
}
3798
3798
3799
-
voiddanglingLifetimeAggegrateConstructor() {
3799
+
voiddanglingLifetimeAggregateConstructor() {
3800
3800
check("struct A {\n"
3801
3801
" const int& x;\n"
3802
3802
" int y;\n"
@@ -3893,6 +3893,30 @@ class TestAutoVariables : public TestFixture {
3893
3893
" return { m.data() };\n"
3894
3894
"}\n");
3895
3895
ASSERT_EQUALS("", errout_str());
3896
+
3897
+
check("struct S { std::string s; };\n"// #13167
3898
+
"std::vector<S> f() {\n"
3899
+
" std::vector<S> v;\n"
3900
+
" {\n"
3901
+
" std::string a{ \"abc\" };\n"
3902
+
" v.push_back({ a.c_str() });\n"
3903
+
" }\n"
3904
+
" return v;\n"
3905
+
"}\n");
3906
+
ASSERT_EQUALS("", errout_str());
3907
+
3908
+
check("struct S { std::string_view sv; };\n"
3909
+
"std::vector<S> f() {\n"
3910
+
" std::vector<S> v;\n"
3911
+
" {\n"
3912
+
" std::string a{ \"abc\" };\n"
3913
+
" v.push_back({ a.c_str() });\n"
3914
+
" }\n"
3915
+
" return v;\n"
3916
+
"}\n");
3917
+
ASSERT_EQUALS(
3918
+
"[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:8]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n",
0 commit comments