* cp-gimplify.c (cp_fold) [CONSTRUCTOR]: Don't clobber the input.
authorJason Merrill <jason@redhat.com>
Mon, 18 Jan 2016 15:54:26 +0000 (10:54 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 18 Jan 2016 15:54:26 +0000 (10:54 -0500)
From-SVN: r232524

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c

index fbc1a7c..9325bb0 100644 (file)
@@ -1,5 +1,7 @@
 2016-01-18  Jason Merrill  <jason@redhat.com>
 
+       * cp-gimplify.c (cp_fold) [CONSTRUCTOR]: Don't clobber the input.
+
        * cp-gimplify.c (cp_fold): Remove unnecessary special cases.
 
        PR c++/68767
index 2dc53ae..5c4d3c1 100644 (file)
@@ -2125,9 +2125,22 @@ cp_fold (tree x)
       {
        unsigned i;
        constructor_elt *p;
+       bool changed = false;
        vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (x);
+       vec<constructor_elt, va_gc> *nelts = NULL;
+       vec_safe_reserve (nelts, vec_safe_length (elts));
        FOR_EACH_VEC_SAFE_ELT (elts, i, p)
-         p->value = cp_fold (p->value);
+         {
+           tree op = cp_fold (p->value);
+           constructor_elt e = { p->index, op };
+           nelts->quick_push (e);
+           if (op != p->value)
+             changed = true;
+         }
+       if (changed)
+         x = build_constructor (TREE_TYPE (x), nelts);
+       else
+         vec_free (nelts);
        break;
       }
     case TREE_VEC: