# HG changeset patch # User Christian Kamm # Date 1241962943 -7200 # Node ID 6bae1c30480f6a511e5be2e7360b7083552f4a5c # Parent de7fad0ad2434aa9cf2aa1dd4408c58c910c7ebe Backport D2 CTFE cast behavior to allow cast(char[])char[n] to succeed. diff -r de7fad0ad243 -r 6bae1c30480f dmd/constfold.c --- a/dmd/constfold.c Sun May 10 14:37:30 2009 +0200 +++ b/dmd/constfold.c Sun May 10 15:42:23 2009 +0200 @@ -1049,10 +1049,22 @@ if (type->equals(e1->type) && to->equals(type)) return e1; + Type *tb = to->toBasetype(); + Type *typeb = type->toBasetype(); + + // LDC: ported from D2 to allow char[] ~ char[n] arguments in CTFE + if (e1->op == TOKstring) + { + if (tb->ty == Tarray && typeb->ty == Tarray && + tb->nextOf()->size() == typeb->nextOf()->size()) + { + return expType(to, e1); + } + } + if (e1->isConst() != 1) return EXP_CANT_INTERPRET; - Type *tb = to->toBasetype(); if (tb->ty == Tbool) e = new IntegerExp(loc, e1->toInteger() != 0, type); else if (type->isintegral()) @@ -1061,7 +1073,7 @@ { dinteger_t result; real_t r = e1->toReal(); - switch (type->toBasetype()->ty) + switch (typeb->ty) { case Tint8: result = (d_int8)r; break; case Tchar: @@ -1126,7 +1138,7 @@ else { error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars()); - e = new IntegerExp(loc, 0, type); + e = new IntegerExp(loc, 0, Type::tint32); } return e; }