digitalmars.D.bugs - [Issue 1316] New: Can't directly reference members of CTFE struct arrays
- d-bugmail puremagic.com (45/45) Jul 05 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1316
- d-bugmail puremagic.com (4/4) Jul 23 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1316
- d-bugmail puremagic.com (13/13) Sep 01 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1316
http://d.puremagic.com/issues/show_bug.cgi?id=1316 Summary: Can't directly reference members of CTFE struct arrays Product: D Version: 1.018 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: clugdbug yahoo.com.au Two variations, with different error messages. ---------------- struct S { int a; } int func() { S [] s = [S(7)]; return s[0].a; // Error: cannot evaluate func() at compile time } void main() { const int x = func(); } -------------- VARIANT 2 (attempted workaround): -------------- struct S { int a; } int func() { S [] s = [S(7)]; return (s[0]).a; // Fails: // bug.d(9): Error: s is used as a type // bug.d(9): Error: no property 'a' for type 'void[0u]' } void main() { const int x = func(); } ---------- Workaround is to index the array first, then access the member. ---------- int func() { S [] s = [S(7)]; auto q = s[0]; return q.a; // OK } --
Jul 05 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1316 ------- Comment #1 from clugdbug yahoo.com.au 2007-07-23 09:54 ------- The first (and most important) variant seems to have been fixed in DMD 1.019. --
Jul 23 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1316 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |WONTFIX ------- Comment #2 from bugzilla digitalmars.com 2007-09-01 03:01 ------- Variant 1 works fine now. Regarding Variant 2: the parentheses in (s[0]) are redundant. The parser interprets them as an attempt at a C-style cast where s[0] then must be a type. I prefer to leave that in, as it diagnoses attempts to use C-style casts. To fix the code, just remove the redundant parentheses. --
Sep 01 2007