[Issue 3569] DMD Stack Overflow with a struct member function inside a C-style struct initializer

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 29 12:32:10 PST 2009


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


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

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


--- Comment #2 from Don <clugdbug at yahoo.com.au> 2009-12-29 12:32:09 PST ---
This patch to AssertExp::interpret() prevents the stack overflow, turning it
into a simple error message. It doesn't patch the regression.
As Rob notes, the static struct initializers are evaluated at compile time, but
they shouldn't be. Nonetheless, this patch is still required to prevent
segfaults in the case where they are forcibly evaluated at compile time. Eg,
code like the following:

struct Foo {
    Foo bar() { return this; }
}

struct Bar {
    Foo foo;
    int fog() {
        enum Bar r = { foo.bar() };
        return 3;
    }
}

PATCH -----------------------

Index: interpret.c
===================================================================
--- interpret.c    (revision 318)
+++ interpret.c    (working copy)
@@ -2535,14 +2535,18 @@
     if( this->e1->op == TOKaddress)
     {   // Special case: deal with compiler-inserted assert(&this, "null
this") 
     AddrExp *ade = (AddrExp *)this->e1;
-    if(ade->e1->op == TOKthis && istate->localThis)       
-    return istate->localThis->interpret(istate);
+    if(ade->e1->op == TOKthis && istate->localThis)
+        if (istate->localThis->op==TOKdotvar
+          && ((DotVarExp *)(istate->localThis))->e1->op==TOKthis)
+        return getVarExp(loc, istate, ((DotVarExp
*)(istate->localThis))->var);
+        else 
+            return istate->localThis->interpret(istate);
     }
-if (this->e1->op == TOKthis)
-{
+    if (this->e1->op == TOKthis)
+    {
     if(istate->localThis)       
-    return istate->localThis->interpret(istate);
-}    
+        return istate->localThis->interpret(istate);
+    }    
     e1 = this->e1->interpret(istate);
     if (e1 == EXP_CANT_INTERPRET)
     goto Lcant;

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