[Issue 23500] std.traits.getUDAs not working properly for overloads

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 16 14:15:08 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23500

Richard Cattermole <alphaglosined at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alphaglosined at gmail.com

--- Comment #1 from Richard Cattermole <alphaglosined at gmail.com> ---
This was rediscovered by a user on Discord.

The deprecation message wasn't very good.

/usr/include/dmd/phobos/std/traits.d(8514): Deprecation:
__traits(getAttributes) may only be used for individual functions, not overload
sets such as: __ctor

I modified the example here to demonstrate how to change their code:

```d
import std.traits;                                                              

void main() {
    enum attr1;
    enum attr2;

    struct A {   
        @attr1
        void foo();
        @attr2
        void foo(int a); 
    }   

    static foreach(overload; __traits(getOverloads, A, "foo")) {
        pragma(msg, getUDAs!(overload, attr2));
    }
}
```

That deprecation message should be improved with more context, although perhaps
there are some improvements that could be done more broadly like giving more
context (i.e. what triggered that instantiation of getUDAs).

--


More information about the Digitalmars-d-bugs mailing list