UDA example

Jacob Carlborg doob at me.com
Mon Aug 19 11:01:39 PDT 2013


On 2013-08-19 19:57, Craig Dillabaugh wrote:
> When I attempt to compile the following example code from the
> section on UDAs
> at:  http://dlang.org/attribute.html
>
> void main(string args[]) {
> template Tuple (T...)
> {
>           alias T Tuple;
> }
>
> enum EEE = 7;
> @("hello") struct SSS { }
> @(3) { @(4) @EEE @SSS int foo; }
>
> alias Tuple!(__traits(getAttributes, foo)) TP;
>
> pragma(msg, TP); // prints tuple(3, 4, 7, (SSS))
> pragma(msg, TP[2]); // prints 7
> }
>
> I get the following errors:
>
> UDAs.d(9): Error: basic type expected, not {
> UDAs.d(9): Error: no identifier for declarator int
> UDAs.d(9): Error: semicolon expected, not '{'
>
> Line 9 is the one starting "@(3) ..."
>
> Is this due to:
>          a. a DMD bug (DMD64 D Compiler v2.063.2, Linux)
>          b. a Documentation bug
>          c. me not properly copying/pasting the example :/
>

Move everything out of "main" and it will work.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list