]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/66536
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Jun 2015 19:29:19 +0000 (19:29 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Jun 2015 19:29:19 +0000 (19:29 +0000)
* tree.c (replace_placeholders_r) [CONSTRUCTOR]: Handle type
mismatch.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@224534 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/g++.dg/cpp1y/var-templ30.C [new file with mode: 0644]

index 5c85c5d152425d8f5113575282a3b1e5509f3626..d2908c20a66c61e582656eae17867d04f859d2c0 100644 (file)
@@ -1,5 +1,9 @@
 2015-06-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/66536
+       * tree.c (replace_placeholders_r) [CONSTRUCTOR]: Handle type
+       mismatch.
+
        PR c++/58063
        * tree.c (bot_manip): Remap SAVE_EXPR.
 
index a52e6f4367f4b53cc52c14f396d543125ac9880f..e6442cd9a458320c95fefb06bbb8cdb5bca224b5 100644 (file)
@@ -2599,7 +2599,12 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
            if (TREE_CODE (*valp) == CONSTRUCTOR
                && AGGREGATE_TYPE_P (type))
              {
-               subob = build_ctor_subob_ref (ce->index, type, obj);
+               /* If we're looking at the initializer for OBJ, then build
+                  a sub-object reference.  If we're looking at an
+                  initializer for another object, just pass OBJ down.  */
+               if (same_type_ignoring_top_level_qualifiers_p
+                   (TREE_TYPE (*t), TREE_TYPE (obj)))
+                 subob = build_ctor_subob_ref (ce->index, type, obj);
                if (TREE_CODE (*valp) == TARGET_EXPR)
                  valp = &TARGET_EXPR_INITIAL (*valp);
              }
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ30.C b/gcc/testsuite/g++.dg/cpp1y/var-templ30.C
new file mode 100644 (file)
index 0000000..e89aa7c
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/66536
+// { dg-do compile { target c++14 } }
+
+template <typename> struct make_impl;
+struct Tuple;
+template <> struct make_impl<Tuple> {};
+struct A {
+  template <typename X> auto operator()(X) { return make_impl<Tuple>(); }
+};
+template <typename> A make;
+template <typename _Tp, int> struct array { _Tp _M_elems; };
+struct Tracked {
+  Tracked(int);
+};
+struct B {
+  Tracked tracker{0};
+};
+template <int> using ct_eq = B;
+auto eq_arrays = make<Tuple>(array<ct_eq<0>, 0>{});