Function Attributes

No access to mutable global/static state. Weakly pure functions may modify their arguments. Strongly pure functions are referentially transparent (enables memoization and implicit immutable conversion of unique results).

Throws no Exception (Errors are still possible) No GC allocation @safe / @trusted / @system Memory safety level Property syntax (mostly informational)

Forbid a function (e.g., @disable this();, @disable this(this);) ref / auto ref / return

const / immutable / inout / shared (on methods) Qualify this

override / final / abstract / static extern(C) / extern(C++) / extern(D) / extern(System) / extern(Objective-C) pragma(inline, true) @mustuse (core.attribute) The result must be used @standalone (core.attribute)

Module constructor independence (cycle avoidance) Attribute inference applies to templates, lambdas, auto return functions, and nested functions.

Common annotation block: @safe pure nothrow @nogc: at the top of a module or struct.

pure nothrow @nogc @safe int square(int x) { return x * x; }

int[] makeArray(int n) pure
{
    auto r = new int[](n);
    foreach (i, ref e; r) e = cast(int) i;
    return r;
}
immutable int[] frozen = makeArray(5);   // OK: the result of a pure function is unique