www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiler complaining about ~ used on static array in nogc fn

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
Referring to: https://auto-tester.puremagic.com/show-run.ghtml?projectid=1&runid=
915054&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?

-- 
Shriramana Sharma, Penguin #395953
Jan 13
parent "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> writes:
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=
915054&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.
Jan 13