As of 2.052 replace() has moved to std.array and uses Appender. Thus it isn't evaluatable at compile-time anymore because Appender uses a pointer to a struct.
import std.array;
int bla()
{
"aa".replace("aa", "bb");
return 0;
}
enum blub = bla();
C:\dmd\windows\bin\..\..\src\phobos\std\array.d(1051): Error: Cannot interpret new Data at compile time
C:\dmd\windows\bin\..\..\src\phobos\std\array.d(1331): Error: cannot evaluate (Appender!(string) __ctmp1239 = 0; , __ctmp1239).this(array) at compile time
C:\dmd\windows\bin\..\..\src\phobos\std\array.d(884): Error: cannot evaluate appender(null) at compile time
replacectfe.d(6): Error: cannot evaluate replace("aa","aa","bb") at compile time
replacectfe.d(10): Error: cannot evaluate bla() at compile time
replacectfe.d(10): Error: cannot evaluate bla() at compile time
Comment #1 by bearophile_hugs — 2011-02-21T09:46:52Z
String functions are better if they are evaluable at compile-time, but currently there is no requirements for the standard library to be CTFE. So I think this is an enhancement request and not a bug.
A simple way to solve this problem is to use __ctfe, to add to replace() another algorithm fit for run-time.
Comment #2 by hoganmeier — 2011-02-21T10:25:05Z
Yeah, I know it is no requirement.
On the other hand you could also see it as a regression since replace was CTFE-able before ;)
But I agree, string functions should be available at compile-time because we need it for string mixins.