D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8388 - std.traits.MemberFunctionsTuple doesn't work with constructors or destructors
Summary: std.traits.MemberFunctionsTuple doesn't work with constructors or destructors
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2012-07-13 22:52 UTC by Jonathan M Davis
Modified: 2020-01-29 09:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2012-07-13 22:52:08 UTC
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 Jonathan M Davis 2012-07-13 23:33:57 UTC
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 Vladimir Panteleev 2017-07-19 07:41:19 UTC
(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 RazvanN 2017-08-28 10:09:13 UTC
PR : https://github.com/dlang/phobos/pull/5710
Comment 4 Dlang Bot 2020-01-29 08:41:13 UTC
@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 Dlang Bot 2020-01-29 09:56:21 UTC
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