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
+38-4Lines changed: 38 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,7 @@ class TestAutoVariables : public TestFixture {
151
151
TEST_CASE(danglingLifetimeImplicitConversion);
152
152
TEST_CASE(danglingTemporaryLifetime);
153
153
TEST_CASE(danglingLifetimeBorrowedMembers);
154
+
TEST_CASE(danglingLifetimeClassMemberFunctions);
154
155
TEST_CASE(invalidLifetime);
155
156
TEST_CASE(deadPointer);
156
157
TEST_CASE(splitNamespaceAuto); // crash #10473
@@ -2246,10 +2247,8 @@ class TestAutoVariables : public TestFixture {
2246
2247
"auto f() {\n"
2247
2248
" return g().begin();\n"
2248
2249
"}");
2249
-
TODO_ASSERT_EQUALS(
2250
-
"[test.cpp:3] -> [test.cpp:3]: (error) Returning iterator that will be invalid when returning.\n",
2251
-
"",
2252
-
errout.str());
2250
+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Returning iterator that will be invalid when returning.\n",
2251
+
errout.str());
2253
2252
2254
2253
check("std::vector<int> f();\n"
2255
2254
"auto f() {\n"
@@ -3291,6 +3290,41 @@ class TestAutoVariables : public TestFixture {
3291
3290
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5] -> [test.cpp:6]: (error) Using pointer that is a temporary.\n",
3292
3291
errout.str());
3293
3292
}
3293
+
3294
+
voiddanglingLifetimeClassMemberFunctions()
3295
+
{
3296
+
check("struct S {\n"
3297
+
" S(int i) : i(i) {}\n"
3298
+
" int i;\n"
3299
+
" int* ptr() { return &i; }\n"
3300
+
"};\n"
3301
+
"int* fun(int i) { \n"
3302
+
" return S(i).ptr();\n"
3303
+
"}\n");
3304
+
ASSERT_EQUALS(
3305
+
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:7] -> [test.cpp:7]: (error) Returning pointer that will be invalid when returning.\n",
3306
+
errout.str());
3307
+
3308
+
check("struct Fred\n"
3309
+
"{\n"
3310
+
" int x[2];\n"
3311
+
" Fred() {\n"
3312
+
" x[0] = 0x41;\n"
3313
+
" x[1] = 0x42;\n"
3314
+
" }\n"
3315
+
" const int *get_x() {\n"
3316
+
" return x;\n"
3317
+
" }\n"
3318
+
"};\n"
3319
+
"static const int *foo() {\n"
3320
+
" Fred fred;\n"
3321
+
" return fred.get_x();\n"
3322
+
"}\n");
3323
+
ASSERT_EQUALS(
3324
+
"[test.cpp:9] -> [test.cpp:9] -> [test.cpp:14] -> [test.cpp:13] -> [test.cpp:14]: (error) Returning pointer to local variable 'fred' that will be invalid when returning.\n",
0 commit comments