[Issue 4001] New: ctfe return value is handled incorrectly when used as template argument

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 24 00:59:54 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4001

           Summary: ctfe return value is handled incorrectly when used as
                    template argument
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jelszonak at gmail.com


--- Comment #0 from Zólyomi István <jelszonak at gmail.com> 2010-03-24 00:59:45 PDT ---
Note that the dmd version I was working with was 2.042, but it was still
unavailable in the version list. The reduced test case is the following:

import std.metastrings;

// dummy ctfe-capable function needed to reproduce the error
long parseLong(string timeStr) { return 42; }

// ctfe-capable function to demonstrate that a value is calculated in
compile-time
string longToStr(long val)
{
    if (val < 10) { return "" ~ cast(char)(val + '0'); }
    else { return longToStr(val / 10) ~ longToStr(val % 10); }
}

void main(string[] args)
{
    const long mylong = parseLong("mystring");
    pragma(msg, "fine ", longToStr(mylong) ); // compiles and prints
    pragma(msg, "bug? ", std.metastrings.toStringNow!(mylong) ); // error
}

For this code, the compiler output is

fine 42
bug? c:\Program Files\.....\src\phobos\std\metastrings.d(97): Error: expression
mylong < 0L is not constant or does not evaluate to a bool

I think this is a bug, toStringNow should work just as like longToStr. I
checked its source code, but found no reason for the compile error, it seems to
do the same thing with templates as longToStr with ctfe. The bug was confirmed
on the newsgroups, see thread starting with

http://digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=107973

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


More information about the Digitalmars-d-bugs mailing list