Possible UDA bug

Maxim Fomin maxim at maxim-fomin.ru
Sun Feb 24 11:16:47 PST 2013


On Sunday, 24 February 2013 at 18:03:29 UTC, jerro 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.

No, you are misunderstanding the spec. __traits(getAttributes, 
foo) is CT expression. The reason why it does not work in your 
example is because you deliberately placed sourceless function 
which is required for evaluation. Your case is close to:

int foo();

int bar() { return foo(); }

enum x = bar();

void main(){}

So, there is nothing wrong with calling CTFE function from other. 
The (deliberately created) problems arise when function is 
sourceless.


More information about the Digitalmars-d mailing list