Bug 15094 – __traits(getMember) fails when the source is a struct/class field
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-21T15:49:24Z
Last change time
2021-01-03T22:57:06Z
Keywords
industry, pull, rejects-valid
Assigned to
No Owner
Creator
Alex Parrill
Comments
Comment #0 by initrd.gz — 2015-09-21T15:49:24Z
Attempting to use `__traits(getMember)` with a sub-struct/field fails with a `need 'this'` error.
Example code:
import std.stdio;
struct Foo {
int i;
}
struct Bar {
Foo foo;
}
void main() {
Bar bar;
writeln(__traits(getMember, bar.foo, "i"));
}
Output:
$ rdmd ~/test.d
/home/col/test.d(14): Error: need 'this' for 'i' of type 'int'
Failed: ["dmd", "-v", "-o-", "/home/col/test.d", "-I/home/col"]
It's possible, but annoying, to work around this by storing a local pointer to the field first.
auto foo = &bar.foo;
writeln(__traits(getMember, foo, "i"));
Comment #1 by dlang-bugzilla — 2015-10-15T17:22:38Z
(In reply to Vladimir Panteleev from comment #1)
> This appears to be a regression.
>
> Introduced in https://github.com/D-Programming-Language/dmd/pull/1687
Not correct. With 2.062, compiling example code with `dmd -c` will make:
test.d(16): Error: need 'this' to access member foo
PR 1687 had moved many "need this" errors in glue layer to front-end, but such the field access is not yet supported. I think it's a reject-valid bug.
Comment #3 by dlang-bugzilla — 2015-10-21T03:30:09Z
(In reply to Kenji Hara from comment #2)
> PR 1687 had moved many "need this" errors in glue layer to front-end, but
> such the field access is not yet supported. I think it's a reject-valid bug.
Oh, OK.
dlang/dmd pull request #12093 "[dmd-cxx] Backport more recent traits to the C++ port" was merged into dmd-cxx:
- 542f9a47d165eb27b2d3b937cadd119c779b07fe by JinShil:
[dmd-cxx] Fix Issue 15094 - __traits(getMember) fails when the source is a struct/class field
https://github.com/dlang/dmd/pull/12093