www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5632] New: replace() not evaluatable at compile-time anymore

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5632

           Summary: replace() not evaluatable at compile-time anymore
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de
        Depends on: 4047



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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5632


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5632




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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5632


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED
            Summary|replace() not evaluatable   |[CTFE] replace() not
                   |at compile-time anymore     |evaluatable at compile-time
                   |                            |anymore



https://github.com/D-Programming-Language/phobos/commit/337a6182d33b43e80a82a052d63ff1118ff39116

(together with the DMD changes which make this possible).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2011