struct S { static void foo(T)(int i) {} static void foo(T)(string s) {} } alias foo0 = __traits(getOverloads, S, "foo", true)[0]; alias bar0 = foo0!long; // Error: template `S.foo` matches more than one template declaration alias foo1 = __traits(getOverloads, S, "foo", true)[1]; alias bar1 = foo1!int; // works fine Trying to use the first overload is behaving exactly as if I were using S.foo directly.
@rmanthorpe created dlang/dmd pull request #11431 "Fix Issue 21050 - __traits(getOverloads) for templates returns incorr…" fixing this issue: - Fix Issue 21050 - __traits(getOverloads) for templates returns incorrect symbol for the first overload https://github.com/dlang/dmd/pull/11431
dlang/dmd pull request #11431 "Fix Issue 21050 - __traits(getOverloads) for templates returns incorr…" was merged into master: - 9194d3aa930140cbd24829d4fb860e615b581c36 by Richard Manthorpe: Fix Issue 21050 - __traits(getOverloads) for templates returns incorrect symbol for the first overload Template declarations are nodes in a linked list of overloads. Returning a template declaration from __traits(getOverloads) returned the tail of that list of overloads. Instead we must take a copy of the template declaration and remove references to overnext and overroot so that it is no longer part of the overload set. https://github.com/dlang/dmd/pull/11431