aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2021-04-27 14:18:25 -0400
committerPatrick Palka <ppalka@redhat.com>2021-04-27 14:18:25 -0400
commit37d2b98100cefcb9d312d379473c12aa6d61fc62 (patch)
tree49b2e2ad017d1b3dcba89fcc2a1356a9c7b42dc7 /gcc
parent85ef4b8d4eb3313a48b79c7e752891f9646bb246 (diff)
downloadgcc-37d2b98100cefcb9d312d379473c12aa6d61fc62.zip
gcc-37d2b98100cefcb9d312d379473c12aa6d61fc62.tar.gz
gcc-37d2b98100cefcb9d312d379473c12aa6d61fc62.tar.bz2
c++: Fix Bases(args...)... base initialization [PR88580]
When substituting into the arguments of a base initializer pack expansion, tsubst_initializer_list uses a dummy EXPR_PACK_EXPANSION in order to expand an initializer such as Bases(args)... into Bases#{0}(args#{0}) and so on. But when an argument inside the base initializer is itself a pack expansion, as in Bases(args...)..., the argument is already an EXPR_PACK_EXPANSION so we don't need to wrap it. It's also independent from the outer expansion of Bases, so we need to "multiplicatively" append the expansion of args... onto the argument list of each expanded base. gcc/cp/ChangeLog: PR c++/88580 * pt.c (tsubst_initializer_list): Correctly handle the case where an argument inside a base initializer pack expansion is itself a pack expansion. gcc/testsuite/ChangeLog: PR c++/88580 * g++.dg/cpp0x/variadic182.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.c28
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/variadic182.C18
2 files changed, 38 insertions, 8 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 8c3c814..eaf4665 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -26389,9 +26389,16 @@ tsubst_initializer_list (tree t, tree argvec)
tree expanded_exprs;
/* Expand the argument. */
- SET_PACK_EXPANSION_PATTERN (expr, TREE_VALUE (arg));
+ tree value;
+ if (TREE_CODE (TREE_VALUE (arg)) == EXPR_PACK_EXPANSION)
+ value = TREE_VALUE (arg);
+ else
+ {
+ value = expr;
+ SET_PACK_EXPANSION_PATTERN (value, TREE_VALUE (arg));
+ }
expanded_exprs
- = tsubst_pack_expansion (expr, argvec,
+ = tsubst_pack_expansion (value, argvec,
tf_warning_or_error,
NULL_TREE);
if (expanded_exprs == error_mark_node)
@@ -26400,12 +26407,17 @@ tsubst_initializer_list (tree t, tree argvec)
/* Prepend each of the expanded expressions to the
corresponding TREE_LIST in EXPANDED_ARGUMENTS. */
for (i = 0; i < len; i++)
- {
- TREE_VEC_ELT (expanded_arguments, i) =
- tree_cons (NULL_TREE,
- TREE_VEC_ELT (expanded_exprs, i),
- TREE_VEC_ELT (expanded_arguments, i));
- }
+ if (TREE_CODE (TREE_VALUE (arg)) == EXPR_PACK_EXPANSION)
+ for (int j = 0; j < TREE_VEC_LENGTH (expanded_exprs); j++)
+ TREE_VEC_ELT (expanded_arguments, i)
+ = tree_cons (NULL_TREE,
+ TREE_VEC_ELT (expanded_exprs, j),
+ TREE_VEC_ELT (expanded_arguments, i));
+ else
+ TREE_VEC_ELT (expanded_arguments, i)
+ = tree_cons (NULL_TREE,
+ TREE_VEC_ELT (expanded_exprs, i),
+ TREE_VEC_ELT (expanded_arguments, i));
}
in_base_initializer = 0;
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic182.C b/gcc/testsuite/g++.dg/cpp0x/variadic182.C
new file mode 100644
index 0000000..078de74
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic182.C
@@ -0,0 +1,18 @@
+// PR c++/88580
+// { dg-do compile { target c++11 } }
+
+template <class... Bases>
+struct Derived : Bases... {
+ template <class... Ts>
+ Derived(Ts... args) : Bases(args, args..., args)... { }
+};
+
+struct A { };
+struct B { };
+struct C { };
+
+struct Base1 { Base1(A, A, B, C, A); };
+struct Base2 { Base2(B, A, B, C, B); };
+struct Base3 { Base3(C, A, B, C, C); };
+
+Derived<Base1, Base2, Base3> d(A{}, B{}, C{});