[Issue 5667] New: "clear" does not call destructors on embedded structs
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 28 10:56:29 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5667
Summary: "clear" does not call destructors on embedded structs
Product: D
Version: D1 & D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: samukha at voliacable.com
--- Comment #0 from Max Samukha <samukha at voliacable.com> 2011-02-28 10:53:40 PST ---
import std.traits;
import std.conv;
import core.stdc.stdlib;
struct S
{
static int dtorCalled;
~this()
{
dtorCalled++;
}
}
class C
{
S s;
}
struct S2
{
S s;
}
void main()
{
// 1
enum size = __traits(classInstanceSize, C);
auto buf = malloc(size)[0..size];
emplace!C(buf);
clear(buf);
assert(S.dtorCalled == 1);
free(buf.ptr);
// 2
S2* s2 = cast(S2*)malloc(S2.sizeof);
clear(*s2);
assert(S.dtorCalled == 2);
free(cast(void*)s2);
}
While a solution to case 2 can be hacked up, case 1 requires a correct
destructor (one that calls destructors on the embedded objects and desirably
the base class destructor) and a pointer to that destructor in the classinfo.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list