[Issue 1316] New: Can't directly reference members of CTFE struct arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 5 09:08:39 PDT 2007


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 at digitalmars.com
        ReportedBy: clugdbug at 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
}


-- 



More information about the Digitalmars-d-bugs mailing list