D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1948 - CTFE fails when mutating a struct in an array
Summary: CTFE fails when mutating a struct in an array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2008-03-26 12:47 UTC by Max Samukha
Modified: 2014-02-24 15:32 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2008-03-26 12:47:43 UTC
Error: cannot evaluate foo() at compile time

struct S
{
    int x;
}

int foo()
{
    S[] a = [];
    a ~= S();
    
    a[0].x = 1; // Fails 

    return 0;
}

enum x = foo();

Btw, CTFE is relatively difficult to debug. More informative messages than "cannot evaluate ... at compile time" would be appreciated.
Comment 1 Don 2009-02-19 07:04:04 UTC
This applies to D1.0 as well.

For D1.0, change last line of test case to:
int x = foo();

Comment 2 Don 2009-07-24 02:21:17 UTC
Patch included in patch for bug#2569.
Comment 3 Walter Bright 2009-09-03 13:23:18 UTC
Fixed dmd 1.047 and 2.032