Skip to content

Commit b6a1915

Browse files
committed
add test
1 parent 56173f2 commit b6a1915

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

test/testclass.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TestClass : public TestFixture {
5959
TEST_CASE(copyConstructor4); // base class with private constructor
6060
TEST_CASE(copyConstructor5); // multiple inheritance
6161
TEST_CASE(copyConstructor6); // array of pointers
62+
TEST_CASE(deletedMemberPointer); // deleted member pointer in destructor
6263
TEST_CASE(noOperatorEq); // class with memory management should have operator eq
6364
TEST_CASE(noDestructor); // class with memory management should have destructor
6465

@@ -1081,6 +1082,33 @@ class TestClass : public TestFixture {
10811082
errout_str());
10821083
}
10831084

1085+
void deletedMemberPointer() {
1086+
1087+
// delete ...
1088+
checkCopyConstructor("struct P {};\n"
1089+
"class C {\n"
1090+
" P *p;\n"
1091+
"public:\n"
1092+
" explicit C(P *p) : p(p) {}\n"
1093+
" ~C() { delete p; }\n"
1094+
" void f() {}\n"
1095+
"};\n");
1096+
ASSERT_EQUALS("[test.cpp:6:19]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\n"
1097+
"[test.cpp:6:19]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\n", errout_str());
1098+
1099+
// free(...)
1100+
checkCopyConstructor("struct P {};\n"
1101+
"class C {\n"
1102+
" P *p;\n"
1103+
"public:\n"
1104+
" explicit C(P *p) : p(p) {}\n"
1105+
" ~C() { free(p); }\n"
1106+
" void f() {}\n"
1107+
"};\n");
1108+
ASSERT_EQUALS("[test.cpp:6:17]: (warning) Class 'C' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\n"
1109+
"[test.cpp:6:17]: (warning) Class 'C' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\n", errout_str());
1110+
}
1111+
10841112
void noOperatorEq() {
10851113
checkCopyConstructor("struct F {\n"
10861114
" char* c;\n"

0 commit comments

Comments
 (0)