On 2 January 2013 17:44, Kai Nacke <[email protected]> wrote: > Hi! > > While trying to port LDC to PPC64 I ran into the following CTFE issue. This > small program (reduced from std.conv.to!string(int)): > > import core.stdc.stdio : printf; > > string toStr() > { > char x[]; > x.length = 16; > x[0..3] = "666"; > x.length = 3; > return cast(string) x; > } > > string gencode() > { > return "int x = " ~ toStr ~ ";"; > } > > void main() > { > mixin(gencode()); > printf("Value of gencode: |%s|\n", gencode().ptr); > } > > produces the error: > bug2.d(19): Error: expression expected, not 'EOF' > bug2.d(19): Error: semicolon expected, not 'EOF' > (the mixin statement is in line 19) > > From the log I conclude that it must have something to do with the split > range and array join: > > bug2.d(8) VarExp::interpret() x > REF ASSIGN: x=['6', '6', '6'] > ARRAY LITERAL type=char[] 0x10011b59040: > void > void > void > bug2.d(9) ReturnStatement::interpret(cast(string)x) > bug2.d(9) CastExp::interpret() cast(string)x > bug2.d(9) VarExp::interpret() x > RETURN bug2.d(9) > ARRAY LITERAL type=char[] 0x10011b59040: > void > void > void
Something has gone wrong by this point. x is still [void, void, void], when it should be ['6','6','6']. Looks as though the assignment didn't happen properly. > Does anybody have a hint how I can reduce this further? E.g. is there a way > to view the content of the array? showCtfeExpr(arr). Probably you can get a reduced test case like static assert(toStr()=="666"); I don't think the mixin bit is relevant, unless it's a compilation order issue. > > Thanks in advance. > > Kai > > > _______________________________________________ > dmd-internals mailing list > [email protected] > http://lists.puremagic.com/mailman/listinfo/dmd-internals _______________________________________________ dmd-internals mailing list [email protected] http://lists.puremagic.com/mailman/listinfo/dmd-internals
