D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6517 - [CTFE] ptr++ doesn't work but ++ptr does
Summary: [CTFE] ptr++ doesn't work but ++ptr does
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: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-08-17 04:45 UTC by David Simcha
Modified: 2015-06-09 05:15 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 David Simcha 2011-08-17 04:45:24 UTC
int ctfeFun(const int[] arr) {
    auto startp = arr.ptr;
    auto endp = arr.ptr + arr.length;
    
    for(; startp < endp; startp++) {}
    
    return 0;
}

const arr = [1, 2, 3];
enum ans = ctfeFun(arr);

test9.d(5): Error: pointer expression startp++ cannot be interpreted at compile time
test9.d(11): Error: cannot evaluate ctfeFun(arr) at compile time

Changing startp++ to ++startp fixes the problem.
Comment 1 nsf 2011-08-17 14:06:47 UTC
I can confirm it. But in my case it's 'p--' which cannot be interpreted at compile-time, when ++p somewhere in the code works just fine. 'p' is 'const(char)*'.