Bug 16206 – traits getOverloads fails when one of the overload is a templatized function
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-26T15:06:08Z
Last change time
2021-01-03T22:57:08Z
Keywords
industry
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2016-06-26T15:06:08Z
And the declaration order matters:
struct Foo
{
void foo(A,Z)(A a, Z z){}
void foo(float v){}
}
struct Bar
{
void bar(float v){}
void bar(A,Z)(A a, Z z){}
}
void main()
{
static assert(__traits(getOverloads, Bar, "bar").length > 0); // OK
static assert(__traits(getOverloads, Foo, "foo").length > 0); // FAILS
}
making introspection imprevisible.
Comment #1 by destructionator — 2018-03-10T22:08:42Z
ah yes i just hit this too and was about to submit. same thing on module level
void foo()() {}
void foo(int) {}
void main() {
foo(); // works
foo(0); // also works so they seem to be overloaded...
// yet this empty
pragma(msg, __traits(getOverloads, mixin(__MODULE__), "foo"));
// note: if you swap the order of the declarations above, it will
// actually show one foo in the message
}
This was never fixed - the bug is to do with the order in which the template and non-template overload are declared. If the template is declared last it is fine (as in the DMD tests), otherwise there is a problem.
Comment #6 by b2.temp — 2020-05-15T16:45:28Z
To prevent a breaking change a 3rd trait parameter was added. When you add an optional bool then templates are included, no matter the lexical order.
---
struct Foo
{
void foo(A,Z)(A a, Z z){}
void foo(float v){}
}
struct Bar
{
void bar(float v){}
void bar(A,Z)(A a, Z z){}
}
void main()
{
static assert(__traits(getOverloads, Bar, "bar", true).length == 2);
static assert(__traits(getOverloads, Foo, "foo", true).length == 2);
}
---
There are still overloads bugs, but when alias are used (https://issues.dlang.org/show_bug.cgi?id=20821). This is something else that has to do with the fact that once the alias template parameters are missing the lowering is difficual (declarations cant be lowered like expressions or statements).
In case I'm wrong on the status of 16206 please provide a new test case that justify the reopening.
dlang/dmd pull request #12093 "[dmd-cxx] Backport more recent traits to the C++ port" was merged into dmd-cxx:
- 2f4d3b7d3c9badd4f902343b18548aeda7f10197 by Biotronic:
[dmd-cxx] Fix issue 16206 - getOverloads fails when first overload is template
https://github.com/dlang/dmd/pull/12093