I think it would be a good idea to replace GDC's pragma attribute with UDAs. I I have an implementation of this at https://github.com/jerro/GDC/tree/uda-gcc-attributes. The API consists of a module named gcc.attribute that contains a function template attribute():

auto attribute(A...)(A args) if(A.length > 0 && is(A[0] == string))

This function is used like this:

import gcc.attribute;

@attribute("gdc_attribute_name", arg1, arg2) foo()
{
    ...
}

This adds an attribute gdc_attribute_name(arg, arg2) to foo and is equivalent to

pragma(attribute, gdc_attribute_name(arg1, arg2)) foo()
{
    ....
}

The advantage of using UDAs for GDC attributes is that you can alias them or use typetuples of attributes, possibly depending on the values of template parameters. One possible use case is this:

https://github.com/TurkeyMan/phobos/pull/3#issuecomment-11694942

Using UDAs for attributes would also enable us to remove a bunch of code that currently deals with GDC attributes from GDC's version of the frontend.

I'd like to hear your opinions and suggestions on this.

Reply via email to