2.1.1 Attribute Syntax

@(gcc.attributes.attribute) is the generic entrypoint for applying GCC attributes to a function, variable, or type. There is no type checking done, as well as no deprecation path for attributes removed from the compiler. So the recommendation is to use any of the other UDAs available as described in Common Attributes unless it is a target-specific attribute (See Target-specific Attributes).

Function attributes introduced by the @attribute UDA are used in the declaration of a function, followed by an attribute name string and any arguments separated by commas enclosed in parentheses.

import gcc.attributes;
@attribute("regparm", 1) int func(int size);

Multiple attributes can be applied to a single declaration either with multiple @attribute attributes, or passing all attributes as a comma-separated list enclosed by parentheses.

// Both func1 and func2 have the same attributes applied.
@attribute("noinline") @attribute("noclone") void func1();
@(attribute("noinline"), attribute("noclone")) void func2();

There are some problems with the semantics of such attributes in D. For example, there are no manglings for attributes, although they may affect code generation, so problems may arise when attributed types are used in conjunction with templates or overloading. Similarly, typeid does not distinguish between types with different attributes. Support for attributes in D are restricted to declarations only.