A variant of code:
---
//field size doesn't depend on unittest version (to avoid corruption)
//use `_buff` property to access the buffer
To[256 / To.sizeof] _buffer; // the 'small string optimization'
To[] _buff()
{
version (unittest)
{
// smaller size to trigger reallocations
return _buffer[0..16/To.sizeof];
}
else
{
return _buffer; // production size
}
}
---
Also reallocation logic is quite smart.
Comment #5 by schveiguy — 2017-12-16T15:02:43Z
This is somewhat how the original worked. I have a feeling the compiler was having difficulty proving the return wasn't a piece of the object itself, which is why the latter PR was made.
Comment #6 by github-bugzilla — 2017-12-20T17:43:13Z
dlang/phobos pull request #6947 "[dmd-cxx] Backport Solaris and DragonflyBSD ports" was merged into dmd-cxx:
- a181958b932a5761d7a8f7ab7a05736ce8e3e829 by Steven Schveighoffer:
Fix issue 18084 - tempCString type should not change layout when used in
unittests.
https://github.com/dlang/phobos/pull/6947