This compiles successfully:
struct S {
@nogc
void f() {
scope dlg = { new int; };
}
}
Whereas this doesn't, because it complains the "new" violates @nogc.
struct T {
@nogc:
void f() {
scope dlg = { new int; };
}
}
Comment #1 by eyal — 2021-04-05T22:47:35Z
A pure function incorrectly taints all delegates declared within it as pure as well.
For example, this compiles:
__gshared string global;
struct S {
auto f() {
scope dlg = { throw new Exception(global); };
}
static assert(hasFunctionAttributes!(f, "pure"));
}
But this complains about the use of the global:
struct T {
pure
void f() {
scope dlg = { throw new Exception(global); };
}
}
Comment #2 by eyal — 2021-04-05T22:50:17Z
Interestingly, @safe/nothrow seem to behave just fine.
Comment #3 by robert.schadek — 2024-12-13T19:15:45Z