Compiler complaining about ~ used on static array in @nogc fn
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 13 10:51:30 PST 2016
On Wed, Jan 13, 2016 at 10:23:17PM +0530, Shriramana Sharma via Digitalmars-d-learn wrote:
> Referring to: https://auto-tester.puremagic.com/show-run.ghtml?projectid=1&runid=1915054&isPull=true, the lines in question are
> phobos/std/utf.d (66, 67):
>
> UnsignedStringBuf buf = void;
> msg ~= " (at index " ~ unsignedToTempString(index, buf, 10) ~ ")";
>
> rgrepping through the druntime and phobos sources for this symbol
> UnsignedStringBuf I found:
>
> ./druntime/src/core/internal/string.d:16:alias UnsignedStringBuf = char[20];
>
> So if it's a static array, then it has nothing to do with the GC, and
> appending will not use the GC, right? So why is the compiler
> complaining that I cannot use ~ inside a @nogc function?
[...]
Even though unsignedToTempString() uses a static array, `msg` is a
string, so appending to it using ~ or ~= may cause reallocation. That
violates @nogc.
T
--
Computers shouldn't beep through the keyhole.
More information about the Digitalmars-d-learn
mailing list