Here, "array<ct_eq<0>, 0>{}" produces a CONSTRUCTOR that is not part of
an aggregate initializer for the eq_arrays variable, so we shouldn't try
to treat it as such.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit d3e127fb66647a1f0d8ddffc981cc0c732563815
Author: Jason Merrill <ja...@redhat.com>
Date: Mon Jun 15 21:44:19 2015 -0400
PR c++/66536
* tree.c (replace_placeholders_r) [CONSTRUCTOR]: Handle type
mismatch.
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index a52e6f4..e6442cd 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -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
index 0000000..e89aa7c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ30.C
@@ -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>{});