Destroy elements in reverse order of construction.

Prevents possibility of last element referencing now invalid first element.
This commit is contained in:
Frederich Munch 2017-06-05 19:44:48 -04:00 committed by sftnight
parent 2d141ff840
commit 77bda84fb2
2 changed files with 21 additions and 7 deletions

View File

@ -86,9 +86,11 @@ namespace {
assert (m_RefCnt > 0 && "Reference count is already zero.");
if (--m_RefCnt == 0) {
if (m_DtorFunc) {
char* payload = getPayload();
for (size_t el = 0; el < m_NElements; ++el)
(*m_DtorFunc)(payload + el * m_AllocSize / m_NElements);
assert(m_NElements && "No elements!");
char* Payload = getPayload();
const auto Skip = m_AllocSize / m_NElements;
while (m_NElements-- != 0)
(*m_DtorFunc)(Payload + m_NElements * Skip);
}
delete [] (char*)this;
}

View File

@ -208,6 +208,18 @@ gCling->evaluate("arrV", V);
V // CHECK-NEXT: (cling::Value &) boxes [(Tracer [3]) { @{{.*}}, @{{.*}}, @{{.*}} }]
// Explicitly destory the copies
V = cling::Value()
//CHECK-NEXT: MADE+{10}:dtor
//CHECK-NEXT: MADE+{9}:dtor
//CHECK-NEXT: MADE+{8}:dtor
//CHECK-NEXT: (cling::Value &) <<<invalid>>> @0x{{.*}}
gCling->evaluate("arrV", V);
//CHECK-NEXT: MADE+{11}:copy
//CHECK-NEXT: MADE+{12}:copy
//CHECK-NEXT: MADE+{13}:copy
// Destruct the variables with static storage:
// Destruct arrV:
//CHECK-NEXT: MADE{7}:dtor
@ -217,7 +229,7 @@ V // CHECK-NEXT: (cling::Value &) boxes [(Tracer [3]) { @{{.*}}, @{{.*}}, @{{.*}
// CHECK-NEXT: VAR{3}:dtor
// CHECK-NEXT: REF{1}:dtor
//CHECK-NEXT: MADE+{8}:dtor
//CHECK-NEXT: MADE+{9}:dtor
//CHECK-NEXT: MADE+{10}:dtor
// V going out of scope
//CHECK-NEXT: MADE+{13}:dtor
//CHECK-NEXT: MADE+{12}:dtor
//CHECK-NEXT: MADE+{11}:dtor