Bug 3512 – dchar iteration over string in CTFE fails
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2009-11-15T03:17:00Z
Last change time
2015-06-09T01:27:05Z
Keywords
rejects-valid
Assigned to
nobody
Creator
wbaxter
Comments
Comment #0 by wbaxter — 2009-11-15T03:17:22Z
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 by doob — 2010-01-10T04:14:19Z
This does work for me using dmd 2.037 and later but not using dmd 1.055 on Mac OS X.
Comment #2 by david — 2010-11-11T11:29:47Z
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 by david — 2010-11-11T11:33:52Z
(In reply to comment #2)
Whereas the original code posted by Bill Baxter compiles successfully.
Comment #4 by david — 2010-11-11T11:39:12Z
(In reply to comment #3)
Please ignore comment #3 :)
Comment #5 by johann.macdonagh — 2011-07-09T06:32:18Z
This still fails, and will most likely be fixed by issue 6268.
Comment #6 by clugdbug — 2011-07-22T04:30:24Z
*** Issue 6268 has been marked as a duplicate of this issue. ***