From 7599760d235cf31c8c6013b62fb41cc810b514b6 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 16 Jun 2015 15:29:19 -0400 Subject: [PATCH] re PR c++/66536 (ICE in build_ctor_subob_ref, at cp/tree.c:2534) PR c++/66536 * tree.c (replace_placeholders_r) [CONSTRUCTOR]: Handle type mismatch. From-SVN: r224534 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/tree.c | 7 ++++++- gcc/testsuite/g++.dg/cpp1y/var-templ30.C | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ30.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5c85c5d1524..d2908c20a66 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-06-16 Jason Merrill + PR c++/66536 + * tree.c (replace_placeholders_r) [CONSTRUCTOR]: Handle type + mismatch. + PR c++/58063 * tree.c (bot_manip): Remap SAVE_EXPR. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index a52e6f4367f..e6442cd9a45 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 00000000000..e89aa7c2f24 --- /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 struct make_impl; +struct Tuple; +template <> struct make_impl {}; +struct A { + template auto operator()(X) { return make_impl(); } +}; +template A make; +template struct array { _Tp _M_elems; }; +struct Tracked { + Tracked(int); +}; +struct B { + Tracked tracker{0}; +}; +template using ct_eq = B; +auto eq_arrays = make(array, 0>{}); -- 2.30.2