named arguments, string interpolation, please stop.

Nickolay Bukreyev buknik95 at ya.ru
Fri Jan 12 03:38:07 UTC 2024


On Thursday, 11 January 2024 at 22:49:51 UTC, Guillaume Piolat 
wrote:
> @nogc could get an escape hatch maybe?
> pure is especially annoying because no escape hatch.
>
> Perhaps we can live with their UB in a per-attribute basis.
> UB of @nogc is allocating  with GC, it only annoys in cases 
> without GC, else well, type system was broken.

There is an escape hatch for them already.

```d
void fakeNoGc(ref Appender!string) @nogc;

pragma(mangle, fakeNoGc.mangleof)
void fakeNoGcImpl(ref Appender!string app) {
     app ~= "text";
}

void test() {
     auto app = appender!string();
     app.reserve(8);
     () @nogc {
         fakeNoGc(app); // If it actually reallocates, it's UB.
     }();
}
```

The compiler blindly trusts us that `fakeNoGc` won’t touch the 
GC. It does not check anything.

It’s a very dangerous pattern. Are you certain it needs a more 
convenient syntax?


More information about the Digitalmars-d mailing list