CPP: Add test cases with lambdas.

This commit is contained in:
Geoffrey White
2018-12-11 15:26:59 +00:00
parent 06dd5f3616
commit 77c1ad47f9
2 changed files with 39 additions and 0 deletions

View File

@@ -10,6 +10,9 @@
| DeleteThis.cpp:60:3:60:24 | ... = ... | Resource ptr14 is acquired by class MyClass3 but not released anywhere in this class. |
| DeleteThis.cpp:127:3:127:20 | ... = ... | Resource d is acquired by class MyClass9 but not released anywhere in this class. |
| ExternalOwners.cpp:49:3:49:20 | ... = ... | Resource a is acquired by class MyScreen but not released anywhere in this class. |
| Lambda.cpp:7:3:7:21 | ... = ... | Resource r1 is acquired by class testLambda but not released anywhere in this class. |
| Lambda.cpp:12:3:12:21 | ... = ... | Resource r2 is acquired by class testLambda but not released anywhere in this class. |
| Lambda.cpp:24:3:24:21 | ... = ... | Resource r4 is acquired by class testLambda but not released anywhere in this class. |
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |

View File

@@ -0,0 +1,36 @@
class testLambda
{
public:
testLambda()
{
r1 = new char[4096]; // GOOD [FALSE POSITIVE]
deleter1 = [](char *r) {
delete [] r;
};
r2 = new char[4096]; // GOOD [FALSE POSITIVE]
auto deleter2 = [this]() {
delete [] r2;
};
deleter2();
r3 = new char[4096]; // GOOD
auto deleter3 = [&r = r3]() {
delete [] r;
};
deleter3();
r4 = new char[4096]; // BAD
}
~testLambda()
{
deleter1(r1);
}
private:
char *r1, *r2, *r3, *r4;
void (*deleter1)(char *r);
};