Issue 3512 - dchar iteration over string in CTFE fails
Summary: dchar iteration over string in CTFE fails
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
: 6268 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-11-15 03:17 UTC by Bill Baxter
Modified: 2015-06-09 01:27 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Bill Baxter 2009-11-15 03:17:22 UTC
Code:
    string s = "ohai";
    foreach (int i, dchar c; s)
    {}


Error:
Error: cannot evaluate _aApplycd2(s,int delegate(ref int __applyArg0, ref dchar __applyArg1)
{
dchar c2 = __applyArg1;
int i = __applyArg0;
if (cast(uint)c == cast(uint)c2)
__result = i;
return 2;
return 0;
}
) at compile time


foreach(dchar c; s)  also fails similarly.
Comment 1 Jacob Carlborg 2010-01-10 04:14:19 UTC
This does work for me using dmd 2.037 and later but not using dmd 1.055 on Mac OS X.
Comment 2 David Röthlisberger 2010-11-11 11:29:47 UTC
I'm seeing a similar error. dmd 2.050 on OS X.

Code:
    import std.string;
    void main()
    {
      mixin("int " ~ tolower("A") ~ ";");
    }

Error:

/Users/drothlis/dmd2/osx/bin/../../src/phobos/std/string.d(792): Error: _aApplycd2 cannot be interpreted at compile time, because it has no available source code
minimal.d(5): Error: cannot evaluate tolower("A") at compile time
Comment 3 David Röthlisberger 2010-11-11 11:33:52 UTC
(In reply to comment #2)
Whereas the original code posted by Bill Baxter compiles successfully.
Comment 4 David Röthlisberger 2010-11-11 11:39:12 UTC
(In reply to comment #3)
Please ignore comment #3 :)
Comment 5 Johann MacDonagh 2011-07-09 06:32:18 UTC
This still fails, and will most likely be fixed by issue 6268.
Comment 6 Don 2011-07-22 04:30:24 UTC
*** Issue 6268 has been marked as a duplicate of this issue. ***