odd issue in 1.006
Kevin Bealer
kevinbealer at gmail.com
Sat Feb 17 15:18:26 PST 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;
}
More information about the Digitalmars-d
mailing list