Hi!

For SIZEOF_EXPR, we rely on cp_fold to fold it.
But, for VEC_INIT_EXPR initialization, we actually just genericize it
without ever folding the expressions, so e.g. if the ctor has default args
and some complicated expressions in there, they will never be cp_folded.
This is the only place that calls cp_genericize_tree other than when the
whole function is genericized, the fix just adds similar folding of the
expression that cp_fold_function does.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/6.2?

2016-07-11  Jakub Jelinek  <ja...@redhat.com>

        PR c++/71822
        * cp-gimplify.c (cp_gimplify_expr) <case VEC_INIT_EXPR>: Recursively
        fold *expr_p before genericizing it.

        * g++.dg/template/defarg21.C: New test.

--- gcc/cp/cp-gimplify.c.jj     2016-07-11 11:14:28.000000000 +0200
+++ gcc/cp/cp-gimplify.c        2016-07-11 11:24:30.554083084 +0200
@@ -621,6 +621,8 @@ cp_gimplify_expr (tree *expr_p, gimple_s
                                  init, VEC_INIT_EXPR_VALUE_INIT (*expr_p),
                                  from_array,
                                  tf_warning_or_error);
+       hash_set<tree> pset;
+       cp_walk_tree (expr_p, cp_fold_r, &pset, NULL);
        cp_genericize_tree (expr_p);
        ret = GS_OK;
        input_location = loc;
--- gcc/testsuite/g++.dg/template/defarg21.C.jj 2016-07-11 11:32:34.262266398 
+0200
+++ gcc/testsuite/g++.dg/template/defarg21.C    2016-07-11 11:31:21.000000000 
+0200
@@ -0,0 +1,21 @@
+// PR c++/71822
+// { dg-do compile }
+
+int bar (int);
+
+template <typename T>
+struct A
+{
+  explicit A (int x = bar (sizeof (T)));
+};
+
+struct B
+{
+  A <int> b[2];
+};
+
+void
+baz ()
+{
+  B b;
+}

        Jakub

Reply via email to