Don't know if this is what you want but:

struct Marked {}
struct Attrs (T...) {}

auto bar ()
{
    @Marked int i;
    return Attrs!(__traits(getAttributes, i))();
}

void main ()
{
    writeln(bar()); // prints Attrs!(Marked)()
}

I just want to be able to return an attributed something. How can a function return something that's attributed?

IIUC what Walter said, a function cannot return an attributed value: any internal symbol can be attributed, but these cannot get out.
I can create can attributed value to 'catch' what a function returns, but not automatically:

??? attributedInt()
{
    @("Hello") int i = 1;
    return i;
}

void main()
{
    ??? j = attributedInt();
    // How to have j get the @("Hello") attribute?
}

The only way would be what you suggest:

- extract the attributes from the internal i
- store them in a specially-crafted struct
- return that
- in the external code, catch the returned struct
- extract the artificially stored attributes
- generate a new value with the same attributes.


Ugh.