[Issue 2029] Typesafe variadic functions don't work in CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 23 01:34:49 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2029



--- Comment #9 from Don <clugdbug at yahoo.com.au> 2009-12-23 01:34:48 PST ---
The solution is much, much simpler. The problem is that CTFE doesn't support
casting array literals to their base type, even though it's a no-op!


constfold.c, inside Expression *Cast(Type *type, Type *to, Expression *e1),
line 1095:
------------
    /* Allow casting from one string type to another
     */
    if (e1->op == TOKstring)
    {
    if (tb->ty == Tarray && typeb->ty == Tarray &&
        tb->nextOf()->size() == typeb->nextOf()->size())
    {
        return expType(to, e1);
    }
    }

+    if (e1->op == TOKarrayliteral && typeb == tb)
+        return e1;

    if (e1->isConst() != 1)
    return EXP_CANT_INTERPRET;
--------
And then in interpret.c, we can remove the error message (line 116):

    TypeFunction *tf = (TypeFunction *)tb;
    Type *tret = tf->next->toBasetype();
-    if (tf->varargs)
-    {    cantInterpret = 1;
-    error("Variadic functions are not yet implemented in CTFE");
-    return NULL;
-    }
    // Ensure there are no lazy parameters
    if (tf->parameters)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list