Bug 10096 – Regression (git-head): __traits(allMembers) triggers out of bounds error

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-16T07:15:00Z
Last change time
2013-05-16T16:23:51Z
Keywords
pull
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2013-05-16T07:15:21Z
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 by k.hara.pg — 2013-05-16T09:21:38Z
*** Issue 10095 has been marked as a duplicate of this issue. ***
Comment #2 by k.hara.pg — 2013-05-16T09:24:36Z
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 by andrej.mitrovich — 2013-05-16T10:27:20Z
(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 by github-bugzilla — 2013-05-16T16:23:30Z
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