UDA example

Craig Dillabaugh cdillaba at cg.scs.carleton.ca
Mon Aug 19 10:57:02 PDT 2013


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 :/

Craig

P.S. This reCAPTCHA anti-spam think sucks.


More information about the Digitalmars-d-learn mailing list