Possible UDA bug

Steven Schveighoffer schveiguy at yahoo.com
Sun Feb 24 11:03:34 PST 2013


On Sun, 24 Feb 2013 13:03:26 -0500, jerro <a at a.com> wrote:

>> extern(C) int bar();
>> @bar() void foo(){}
>> //pragma(msg, __traits(getAttributes, foo));
>>
>> void main()
>> {
>>     auto x = __traits(getAttributes, foo)[0];
>> }
>>
>> is compilable and runnable when linker knows where bar() is.
>
> So this is actually supposed to work? The documentation says:
>
>> User Defined Attributes (UDA) are compile time expressions that can be  
>> attached to a declaration.
>
> I guess the documentation is wrong or at least unclear in that case.

It sort of makes sense.  Remember, these are compile-time entities.  If  
nobody every looks at them, there is no need for the compiler to either.

For example, this compiles:

template foo(T)
{
    enum foo = new T;
}

But if you ever try to use it, the compiler will complain.

-Steve


More information about the Digitalmars-d mailing list