suspected ctfe bug
Steven Schveighoffer
schveiguy at yahoo.com
Tue Mar 23 04:52:53 PDT 2010
On Tue, 23 Mar 2010 03:25:25 -0400, Zólyomi István
<istvan.zolyomi at 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
More information about the Digitalmars-d
mailing list