Bug 8388 – std.traits.MemberFunctionsTuple doesn't work with constructors or destructors
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-13T22:52:08Z
Last change time
2020-01-29T09:56:21Z
Keywords
pull
Assigned to
No Owner
Creator
Jonathan M Davis
Comments
Comment #0 by issues.dlang — 2012-07-13T22:52:08Z
This code
import std.stdio;
import std.traits;
class C
{
this() {}
this(int i) {}
this(int i, float j) {}
this(string s) {}
~this() {}
}
void main()
{
writeln(__traits(hasMember, C, "__ctor"));
writeln(__traits(hasMember, C, "__dtor"));
foreach(f; MemberFunctionsTuple!(C, "__ctor"))
writeln(f.stringof);
foreach(f; MemberFunctionsTuple!(C, "__dtor"))
writeln(f.stringof);
}
prints
true
true
The MemberFunctionsTuple results are empty. The constructors and destructor should be listed, but none are. So, clearly, while hasMember properly finds the constructors and destructor, MemberFunctionsTuple does not.
Comment #1 by issues.dlang — 2012-07-13T23:33:57Z
It looks like MermberFunctionsTuple only grabs virtual functions. This code
import std.stdio;
import std.traits;
class C
{
void foo()() {}
void goo() { foo(); }
}
void main()
{
foreach(f; MemberFunctionsTuple!(C, "foo"))
writeln(f.stringof);
foreach(f; MemberFunctionsTuple!(C, "goo"))
writeln(f.stringof);
}
just prints
goo()
foo() isn't printed. So, the constructors and destructor probably aren't being grabbed, because they're non-virtual.
Comment #2 by dlang-bugzilla — 2017-07-19T07:41:19Z
(In reply to Jonathan M Davis from comment #1)
> It looks like MermberFunctionsTuple only grabs virtual functions.
Not virtual - rather, non-templated. It ignores templates. Final functions seem to work fine.
(In reply to Jonathan M Davis from comment #1)
> foo() isn't printed. So, the constructors and destructor probably aren't
> being grabbed, because they're non-virtual.
Pretty sure all class destructors in D are virtual.
Comment #3 by razvan.nitu1305 — 2017-08-28T10:09:13Z
@berni44 created dlang/phobos pull request #7385 "Fix Issue 8388 - std.traits.MemberFunctionsTuple doesn't work with constructors or destructors" fixing this issue:
- Fix Issue 8388 - std.traits.MemberFunctionsTuple doesn't work with
constructors or destructors
https://github.com/dlang/phobos/pull/7385
Comment #5 by dlang-bot — 2020-01-29T09:56:21Z
dlang/phobos pull request #7385 "Fix Issue 8388 - std.traits.MemberFunctionsTuple doesn't work with constructors or destructors" was merged into master:
- c6ef9e136d33f7c03882421f8361bfad341814f6 by Bernhard Seckinger:
Fix Issue 8388 - std.traits.MemberFunctionsTuple doesn't work with
constructors or destructors
https://github.com/dlang/phobos/pull/7385