Bug 5632 – [CTFE] replace() not evaluatable at compile-time anymore

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-02-21T08:14:00Z
Last change time
2011-07-02T23:46:40Z
Keywords
rejects-valid
Assigned to
nobody
Creator
hoganmeier
Depends on
4047

Comments

Comment #0 by hoganmeier — 2011-02-21T08:14:29Z
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.
Comment #3 by clugdbug — 2011-07-02T23:46:40Z