D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7245 - [CTFE] Address of ref foreach parameter changes to point after array
Summary: [CTFE] Address of ref foreach parameter changes to point after array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2012-01-07 21:37 UTC by Denis Shelomovskii
Modified: 2015-06-09 05:10 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2012-01-07 21:37:03 UTC
---
int func() {
    int[2] arr;
    int* ptr;

    foreach(i, ref p; arr) if(i == 0)
        ptr = &p;

    int j = *ptr;
    return 0;
}

enum e = func();
---
Error: array index 2 is out of bounds [0,0][0 .. 2]
Error: CTFE internal error: illegal value __error

Assertion failure: 'isCtfeValueValid(newval)' on line 6369 in file 'interpret.c'
Comment 1 Denis Shelomovskii 2012-01-07 21:57:25 UTC
Another illustration (foreach is in function now):
---
int func() {
    int[2] arr;
    int* ptr;

    void f() {
        //Error: variable __aggr3 is used before initialization
        foreach(i, ref p; arr) if(i == 0)
            ptr = &p;
    }

    f();

    int i = *ptr;
    return 0;
}

enum e = func();
---