[Issue 14903] Destructors for arguments completely broken

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 13 05:23:19 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14903

--- Comment #7 from David Nadlinger <code at klickverbot.at> ---
This patch should fix the issue where no dtors are run at all:

—————

--- a/dmd2/expression.c
+++ b/dmd2/expression.c
@@ -1889,10 +1889,7 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction
*tf,
                     }
                 }
             }
-            if (anythrow && i == lastthrow)
-            {
-                appendToPrefix = false;
-            }
+
             if (appendToPrefix) // don't need to add to prefix until there's
something to destruct
             {
                 Identifier *idtmp = Identifier::generateId("__pfx");
@@ -1901,8 +1898,14 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction
*tf,
                 tmp->semantic(sc);

                 /* Modify the destructor so it only runs if gate==false
+                 * We immediately set the gate to true after the last throwing
argument
+                 * has been constructed, so we can directly fold away the
check.
                  */
-                if (tmp->edtor)
+                if (i == lastthrow)
+                {
+                    tmp->edtor = NULL;
+                }
+                else if(tmp->edtor)
                 {
                     Expression *e = tmp->edtor;
                     e = new OrOrExp(e->loc, new VarExp(e->loc, gate), e);     
 // (gate || destructor)

—————

Previously, the gate was set to true before the last throwing argument, which
is obviously wrong if it indeed throws.

Don't have time to turn this into a proper DMD PR myself at the moment, though.

--


More information about the Digitalmars-d-bugs mailing list