struct S {
void foo() @nogc {} // fine
@nogc void foo() {} // fine
@nogc invariant() {} // fine
invariant() @nogc {} /* compilation errors:
Error: statement expected to be `{ }`, not `@`
Error: basic type expected, not `{`
Error: declaration expected, not `{`
*/
}
That example uses @nogc but it's the same with other attributes like @safe, pure, etc.
Comment #1 by dkorpel — 2022-09-04T19:21:26Z
Notably the same applies to unittest:
```
@nogc unittest {} // fine
unittest @nogc {} // compilation errors with -unittest
```
Comment #2 by nick — 2022-09-05T09:03:56Z
Also for the override attribute:
override void f() {} // ok
void f() override {} // error
Comment #3 by robert.schadek — 2024-12-13T19:24:21Z