Bug 6517 – [CTFE] ptr++ doesn't work but ++ptr does

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-08-17T04:45:00Z
Last change time
2015-06-09T05:15:07Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2011-08-17T04:45:24Z
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 by no.smile.face — 2011-08-17T14:06:47Z
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)*'.
Comment #2 by bugzilla — 2011-08-22T22:46:52Z