D-Programming-Language/phobos — pull request #981 by monarchdodra (2012-11-29 17:30:28+00:00)
Title: fixes in Appender

This contains 2 initial fixes:

1. Initialize data to T.init if the object has an elaborate opAssign, or if it has an elaborate destructor. Without this, data is initialized with garbage, which has disastrous results for objects like RefCounted.
2. Reset data to T.init after relocating, if the object has an elaborate destructor (since the data is *moved*), to avoid double destroy (again, objects like RefCounted).

This raised a question though, when the user provides an array to Appender (which verifies `hasElaborateDestructor`):
Are we allowed to modify the *contents* of that array when relocating (setting it to T.init)?

I'm not entirely sure myself.
Anyways, "commit 3 ( https://github.com/monarchdodra/phobos/commit/491a74aa9642df3692643a873b91fd5a16afd452 )" is conservative, and pre-emptivelly re-allocates to avoid modifying the user's data.

"commit 5 ( https://github.com/monarchdodra/phobos/commit/5d1728352eb3ce2019020210dd6a9a07d5f1ed43 )" is more aggressive, and will only relocate if the original data is const.