Comment #0 by razvan.nitu1305 — 2022-11-21T14:14:53Z
import std.traits;
@safe void main()
{
enum attr1;
enum attr2;
struct A
{
@attr1
void foo();
@attr2
void foo(int a);
}
pragma(msg, getUDAs!(A.foo, attr2));
}
I would expect this to print (attr2), however, it does not print anything.
If I change the example to get attr1 then it works. I expect that for overload sets, getUDAs should iterate through the overloads and report if any of the overloads has the given udas. Right now, it just reports the udas for the first overload it finds.
This has been discovered while trying to fix __traits(getAttributes) in the compiler : https://github.com/dlang/dmd/pull/14554
Comment #1 by alphaglosined — 2023-02-16T14:15:08Z
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).