[Issue 3984] CTFE array assignment for struct members using a temporary slice fails

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 24 12:02:34 PDT 2010


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


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #1 from Don <clugdbug at yahoo.com.au> 2010-03-24 12:02:25 PDT ---
Most of the issues described here are duplicates of bug 1330, or bug 3801.
The segfault is the only new bug here. Here's a reduced test case:

struct Segfault3984 {
    int a;
    this(int x){
      a = x;
    }
}

void bug3984(){
    static assert(Segfault3984(3).a == 3);
}


Root cause:
Struct constructors can result in a situation where a CTFE variable is created
outside of a CTFE function. They need a context to put the variable into.
Effectively, the comma expression acts a very simple function.

PATCH:

Interpret.c line 2641

Expression *CommaExp::interpret(InterState *istate)
{
#if LOG
    printf("CommaExp::interpret() %s\n", toChars());
#endif
    // If the comma returns a temporary variable, it needs to be an lvalue
    // (this is particularly important for struct constructors)
    if (e1->op == TOKdeclaration && e2->op == TOKvar 
       && ((DeclarationExp *)e1)->declaration == ((VarExp*)e2)->var)
    {
+    // If there's no context for the variable to be created in,
+    // we need to create one now.
+    InterState istateComma;
+    if (!istate)
+        istate = &istateComma;

    VarExp* ve = (VarExp *)e2;
    VarDeclaration *v = ve->var->isVarDeclaration();
    if (!v->init && !v->value)
        v->value = v->type->defaultInitLiteral();

-- 
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