D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10096 - Regression (git-head): __traits(allMembers) triggers out of bounds error
Summary: Regression (git-head): __traits(allMembers) triggers out of bounds error
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull
: 10095 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-05-16 07:15 UTC by Andrej Mitrovic
Modified: 2013-05-16 16:23 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-05-16 07:15:21 UTC
import std.conv;

string foo(alias var, T = typeof(var))()
{
    foreach (idx, member; __traits(allMembers, T))
    {
        // Error: array index [2] is outside array bounds [0 .. 2]
        to!string(var.tupleof[idx]);  
    }

    return "";
}

struct S
{
    int i;
    string s;
}

void main()
{
    S s = S(1, "");
    auto x = foo!s;
}

Worked in 2.062, in 2.063:
> Error: array index [2] is outside array bounds [0 .. 2]

Might be related to Issue 10095
Comment 1 Kenji Hara 2013-05-16 09:21:38 UTC
*** Issue 10095 has been marked as a duplicate of this issue. ***
Comment 2 Kenji Hara 2013-05-16 09:24:36 UTC
https://github.com/D-Programming-Language/dmd/pull/2043

By fixing bug 3789, currently compiler generates static member function __xopEquals for S and its TypeInfo.
My compiler change would remove such internal names from the result of __traits(allMembers).
Comment 3 Andrej Mitrovic 2013-05-16 10:27:20 UTC
(In reply to comment #2)
> https://github.com/D-Programming-Language/dmd/pull/2043
> 
> By fixing bug 3789, currently compiler generates static member function
> __xopEquals for S and its TypeInfo.
> My compiler change would remove such internal names from the result of
> __traits(allMembers).

Ok. Btw, the documentation for allMembers trait states:

"Builtin properties are not included."

And it lists __ctor, __dtor *if* they're user-defined (__ctor is not shown if a user doesn't write a constructor). 

So I partially think Issue 10097 might be unnecessary, __xopEquals is internal, but __ctor is not since it's only shown if it's user-defined.

Still, I would like to see Issue 10097 fixed, but I'm afraid we might break a lot of code?
Comment 4 github-bugzilla 2013-05-16 16:23:30 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6ae4b48a10602fbcc1c4c8e07bc12c00b82ba15b
fix Issue 10096 - __traits(allMembers) triggers out of bounds error

Internal member names should not be listed in __traits(allMembers)
- Names starting double underscore does not appear its result.
  __cpctor, __invariant, __xopEquals, __fieldPostBlit,
  __aggrPostBlit, __fieldDtor, __aggrDtor, and others...
- Except __ctor, __dtor, and __postblit. They are already used in Phobos, so
  temporary keep them for backward compatibility.

https://github.com/D-Programming-Language/dmd/commit/d714fb15993e8b03a5588ec3cafeecd366375210
Merge pull request #2043 from 9rnsr/fix10096

[REG2.063a] Issue 10096 - __traits(allMembers) triggers out of bounds error