Thread overview
odd issue in 1.006
Feb 17, 2007
Kevin Bealer
Feb 17, 2007
Walter Bright
Feb 17, 2007
Kevin Bealer
February 17, 2007
In 1.006, this seems to be allowed in a CTFE function:

int q = A[i..j].length;
c += q;

But not this:

c += A[i..j].length;

Kevin
February 17, 2007
Kevin Bealer wrote:
> In 1.006, this seems to be allowed in a CTFE function:
> 
> int q = A[i..j].length;
> c += q;
> 
> But not this:
> 
> c += A[i..j].length;

Both should work. Can you provide a complete example?
February 17, 2007
Walter Bright wrote:
> Kevin Bealer wrote:
>> In 1.006, this seems to be allowed in a CTFE function:
>>
>> int q = A[i..j].length;
>> c += q;
>>
>> But not this:
>>
>> c += A[i..j].length;
> 
> Both should work. Can you provide a complete example?

Sure; in the 'bar' function below, the 'v += A.length' fails, but the previous two lines work just fine as a replacement.  The failure is reported like this:

dmd -ofexa example.d
example.d(26): Error: cannot evaluate (bar)("a b c d") at compile time

Kevin


// -*- c++ -*-

import std.stdio;
import std.string;
import std.file;

// For DMD 1.006

int bar(char[] A)
{
    int v;

    for(int i = 0; i < A.length; i++) {
        if (A[i] != ' ') {
//          int q = A.length; // these work
//          v += q;
            v += A.length; // but this fails
        }
    }

    return v;
}

int main(char[][] args)
{
    const int foo = bar("a b c d");

    return 0;
}