www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - suspected ctfe bug

reply =?ISO-8859-1?Q?Z=f3lyomi_Istv=e1n?= <istvan.zolyomi gmail.com> writes:
Hi,

recently I've been experimenting with the metaprogramming capabilities of the
new dmd 2.042 compiler. I think I've found a bug, but since I'm still not
really experienced with D, please confirm if so. I've reduced the test case to
the following code:

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
}

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

Note that parseLong() is needed to reproduce the bug, if a constant is written
instead of mylong, it works just fine. Am I missing something? 

thanks

István
Mar 23 2010
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 23 Mar 2010 03:25:25 -0400, Zólyomi István  
<istvan.zolyomi gmail.com> wrote:

 Hi,

 recently I've been experimenting with the metaprogramming capabilities  
 of the new dmd 2.042 compiler. I think I've found a bug, but since I'm  
 still not really experienced with D, please confirm if so. I've reduced  
 the test case to the following code:

 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
 }

 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

 Note that parseLong() is needed to reproduce the bug, if a constant is  
 written instead of mylong, it works just fine. Am I missing something?
I think it's a bug. Please file http://d.puremagic.com/issues/enter_bug.cgi -Steve
Mar 23 2010
parent reply =?ISO-8859-1?Q?Z=f3lyomi_Istv=e1n?= <istvan.zolyomi gmail.com> writes:
Steven Schveighoffer Wrote:
 I think it's a bug.  Please file  
 http://d.puremagic.com/issues/enter_bug.cgi
Currently it seems to be down, I'll try not to forget this later. Istvan
Mar 23 2010
parent =?iso-8859-2?Q?Z=F3lyomi_Istv=E1n?= <istvan.zolyomi gmail.com> writes:
Bugzilla entry is

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

Istvan
Mar 24 2010