Bootstrap and regtest running on x86_64-pc-linux-gnu, does this look
OK for trunk/15?
-- >8 --
Since type pack indexes can be cv-qualified, we need to propagate its
qualifiers when substituting into them.
PR c++/122169
gcc/cp/ChangeLog:
* pt.cc (tsubst_pack_index): Propagate cv-qualifiers of a
PACK_INDEX_TYPE.
gcc/testsuite/ChangeLog:
* g++.dg/cpp26/pack-indexing19.C: New test.
---
gcc/cp/pt.cc | 9 +++++++--
gcc/testsuite/g++.dg/cpp26/pack-indexing19.C | 18 ++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp26/pack-indexing19.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index b8039b731b63..f43bf2ef2d50 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -14366,10 +14366,15 @@ tsubst_pack_index (tree t, tree args, tsubst_flags_t
complain, tree in_decl)
tree index = tsubst_expr (PACK_INDEX_INDEX (t), args, complain, in_decl);
const bool parenthesized_p = (TREE_CODE (t) == PACK_INDEX_EXPR
&& PACK_INDEX_PARENTHESIZED_P (t));
+ tree r;
if (!value_dependent_expression_p (index) && TREE_CODE (pack) == TREE_VEC)
- return pack_index_element (index, pack, parenthesized_p, complain);
+ r = pack_index_element (index, pack, parenthesized_p, complain);
else
- return make_pack_index (pack, index);
+ r = make_pack_index (pack, index);
+ if (TREE_CODE (t) == PACK_INDEX_TYPE)
+ r = cp_build_qualified_type (r, cp_type_quals (t) | cp_type_quals (r),
+ complain | tf_ignore_bad_quals);
+ return r;
}
/* Make an argument pack out of the TREE_VEC VEC. */
diff --git a/gcc/testsuite/g++.dg/cpp26/pack-indexing19.C
b/gcc/testsuite/g++.dg/cpp26/pack-indexing19.C
new file mode 100644
index 000000000000..66b82f2aea2c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/pack-indexing19.C
@@ -0,0 +1,18 @@
+// PR c++/122169
+// { dg-do compile { target c++26 } }
+
+template<class T, class U>
+concept same_as = __is_same(T, U);
+
+template<typename... Ts>
+void f() {
+ using T = Ts...[0];
+ static_assert(same_as<const T, const int>);
+
+ []<int I>(auto) {
+ using U = Ts...[I];
+ static_assert(same_as<const U, const int>);
+ }.template operator()<0>(0);
+}
+
+template void f<int>();
--
2.53.0.rc1.65.gea24e2c554