Bug 2358 – offsetof inconsistent between structs and classes
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2008-09-12T05:36:00Z
Last change time
2014-03-01T00:35:58Z
Keywords
rejects-valid, spec
Assigned to
nobody
Creator
kamm-removethis
Comments
Comment #0 by kamm-removethis — 2008-09-12T05:36:43Z
For classes .offsetof works only on the instance and for structs it only works on the declaration:
--
class C { int x; }
struct S { int x; }
void main() {
S s;
C c = new C;
auto c1 = c.x.offsetof;
auto c2 = C.x.offsetof; // error
auto s1 = s.x.offsetof; // error
auto s2 = S.x.offsetof;
}
--
For classes, the situation is documented. For structs, the spec merely says that the offsetof property exists. I expect all combinations could me made legal.
Comment #1 by bugzilla — 2012-01-22T14:04:11Z
auto s1 = s.x.offsetof; // error
works correctly now. The spec does document the current behavior. I hope to remove the restriction on the class .offsetof in the future.