[Issue 2682] const struct initialized with struct literal recreates value on stack when used

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 2 19:46:32 PST 2009


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





------- Comment #2 from tomas at famolsen.dk  2009-03-02 21:46 -------
I fixed this in LDC by disabling the Initializer -> Expression optimization for
StructInitializerS:

--- a/dmd/optimize.c    Tue Mar 03 02:51:21 2009 +0100
+++ b/dmd/optimize.c    Tue Mar 03 04:38:49 2009 +0100
@@ -46,7 +46,7 @@
     if (e1->op == TOKvar)
     {  VarExp *ve = (VarExp *)e1;
        VarDeclaration *v = ve->var->isVarDeclaration();
-       if (v && v->isConst() && v->init)
+       if (v && v->isConst() && v->init && !v->init->isStructInitializer())
        {   Expression *ei = v->init->toExpression();
            if (ei && ei->type)
                e1 = ei;


-- 



More information about the Digitalmars-d-bugs mailing list