[Issue 5895] Object.clear() doesn't work as expected for pointers to structs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 1 21:41:02 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5895



--- Comment #1 from Daniel Gibson <metalcaedes at gmail.com> 2011-05-01 21:37:12 PDT ---
An additional comment: Seems like clear() *is* documented - not in the online
documentation but in TLDP on pages 187/188 (for classes) and 253/254 (for
structs).

It says: "You can invoke a struct object’s destructor explicitly by calling
clear(obj).", and the last code-example included
  auto obj1 = S("first object");
No new there, so it's even correct with the current clear implementation. 
It doesn't mention that clear doesn't work with "auto obj = new S("blah");".

And TLDP doesn't mention at all (at least on the pages the index lists for
"clear") that clear can be used with simple types and even pointers, setting
them to T.init.

So I'd suggest to only allow clear() for (class-) Objects, structs and pointers
to structs (in that case dereferencing the pointer and clearing the struct).
If something like clear() that is so generic that it works for *any* type is
needed, just add another function that does what clear() currently does.

-- 
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