D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7608 - __traits(allMembers) is broken
Summary: __traits(allMembers) is broken
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2012-02-29 03:08 UTC by Andrej Mitrovic
Modified: 2012-03-27 17:03 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-02-29 03:08:58 UTC
import std.stdio;

struct Base(bool T)
{
    static if (T)
    {
        int x;
    }
    
    int y;
}

void main()
{
    alias Base!false Type;
    auto fields = [__traits(allMembers, Type)];

    writeln(fields);  // writes ["x", "y"]
}

"x" does not exist in the Base!false instance.
Comment 1 Andrej Mitrovic 2012-02-29 03:12:24 UTC
Actually
Comment 2 Andrej Mitrovic 2012-02-29 03:13:06 UTC
Actually it's broken for non-template types too:

import std.stdio;
import std.traits;

struct Base
{
    version(none)
    {
        int x;
    }
    
    int y;
}

void main()
{
    auto vals = [__traits(allMembers, Base)];
    writeln(vals);  // writes ["x", "y"]
}
Comment 4 github-bugzilla 2012-03-27 14:32:13 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/ebd56ebac678ddd526a5ccad1787fbfa31530aaa
Merge pull request #832 from 9rnsr/fix7608

Issue 7608 - __traits(allMembers) is broken