Contract error string generation is not implicitly @nogc

Ali Çehreli acehreli at yahoo.com
Sun Sep 4 14:06:44 UTC 2022


void foo(string s) @safe pure nothrow @nogc
in (s != "hello", "Invalid " ~ s) {
}

void main() {}

Error: cannot use operator `~` in `@nogc` function `deneme.foo`

But that operator is used only when we are about to throw an Error, 
which is supposed to imply we shouldn't continue with the program 
anyway. So, just one little GC allocation wouldn't hurt, right? :)

Is there any downside to allowing GC allocation in that case?

Otherwise, we have to throw away either @nogc annotation or the 
functionality of providing useful error messages.

Ali


More information about the Digitalmars-d mailing list