Contract error string generation is not implicitly @nogc

IGotD- nise at nise.com
Sun Sep 4 14:30:51 UTC 2022


On Sunday, 4 September 2022 at 14:06:44 UTC, Ali Çehreli wrote:
> 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? :)
>

...but what if the GC is totally disabled or not even 
initialized? This might be the environment you'd want to use 
@nogc.


More information about the Digitalmars-d mailing list